SlideShare uma empresa Scribd logo
1 de 33
LOGICAL EXPRESSIONS
 IF STATEMENT
SWITCH STATEMENT
Selection Statements
Flow of Control
 Unless specified , the order of statement execution
through a C program is linear: one statement after
the other, in sequence.
 Some programming statements modify that
order, allowing us to:
 decide whether or not to execute a particular statement, or
perform a statement over and over, repetitively
3
Flow of Control
 These decisions are based on a boolean Or logical
expression (also called a condition) that evaluates to
true or false
 The order of statement execution is called the flow of
control
Flow of Control
Sequential Flow
Flow of Control
Selection Statements
Flow of Control
Repetition
Logical Expression
 Logical expression is an expression which uses one
or more logical operators, e.g.,
 (temperature > 90.0 && humidity > 0.90)
 !(n <= 0 || n >= 100).
 The output of the logical expression is the boolean
value either true or false.
If Statements
 If statements consists of boolean expression followed
by one or more statements.
 If the boolean expression evaluates to true, the
statements inside the block get executed otherwise
the first statement outside the block get executed.
 The false value is o and all the other values are
evaluated as true in C.
If Statement
 The syntax of an If statement in C Program is given
below
If Statements
If Statement(Example)
Output
If…else Statement
 If statements can be followed by the optional else
statements, which get executed when the boolean
expression is false.
If…else Statement
If…else Statement(Example)
If…else Statement
If…elseif…else Statement
 If statement can be followed by optional elseif..else
statement, which is very useful to test various
conditions using single if…elseif statement.
 Following things should be kept in mind
 An if can have zero or one else's and it must come after any
else if's.
 An if can have zero to many else if's and they must come
before the else.
 Once an else if succeeds, none of the remaining else if's or
else's will be tested.
If…elseif…else Statement
If…elseif…else Statement(Example)
#include <stdio.h>
#include<conio.h>
int main ()
{
int a = 100;
if( a == 10 )
{
printf("Value of a is 10n" );
}
else if( a == 20 )
{
printf("Value of a is 20n" );
}
else if( a == 30 )
{
printf("Value of a is 30n" );
}
else
{
printf("None of the values is
matchingn" );
}
printf("Exact value of a is:
%dn", a );
getch();
return 0;
}
If…elseif…else Statement
Nested if Statements
 It is always legal in C programming to nest if-else
statements, which means we can use one if or else if
statement inside another if or else if statement(s).
Nested if Statements
#include <stdio.h>
#include <conio.h>
int main ()
{
int a = 100;
int b = 200;
if( a == 100 )
{
if( b == 200 )
{
printf("Value of a is 100
and b is 200n" );
}
}
printf("Exact value of a is :
%dn", a );
printf("Exact value of b is :
%dn", b );
getch();
return 0;
}
Nested if Statements
Switch Statement
 A switch statement allows a variable to be tested for
equality against a list of values.
 Each value is called a case, and the variable being
switched on is checked for each switch case.
 The following rules apply to a switch statement:
 The expression used in a switch statement must have an integral or
enumerated type, or be of a class type in which the class has a single
conversion function to an integral or enumerated type.
 You can have any number of case statements within a switch. Each
case is followed by the value to be compared to and a colon.
 The constant-expression for a case must be the same data type as the
variable in the switch, and it must be a constant or a literal.
Switch Statement
 When the variable being switched on is equal to a case, the
statements following that case will execute until a break
statement is reached.
 When a break statement is reached, the switch terminates, and
the flow of control jumps to the next line following the switch
statement.
 Not every case needs to contain a break. If no break
appears, the flow of control will fall through to subsequent
cases until a break is reached.
 A switch statement can have an optional default case, which
must appear at the end of the switch. The default case can be
used for performing a task when none of the cases is true. No
break is needed in the default case.
Switch Statement
Switch Statement
Switch Statement
#include <stdio.h>
#include <conio.h>
int main ()
{
char grade = 'B';
switch(grade)
{
case 'A' :
printf("Excellent!n" );
break;
case 'B' :
case 'C' :
printf("Well donen" );
break;
case 'D' :
printf("You passedn" );
break;
case 'F' :
printf("Better try againn" );
break;
default :
printf("Invalid graden" );
}
printf("Your grade is
%cn", grade );
getch();
return 0;
}
Switch Statement
Nested Switch Statements
 It is possible to have a switch as part of the statement
sequence of an outer switch.
 Even if the case constants of the inner and outer
switch contain common values, no conflicts will
arise.
Nested Switch Statements
Nested Switch Statements
#include <stdio.h>
#include <conio.h>
int main ()
{
int a = 100;
int b = 200;
switch(a)
{
case 100:
printf("This is part of outer
switchn", a );
switch(b)
{
case 200:
printf("This is part of inner
switchn", a );
}
}
printf("Exact value of a is : %dn", a
);
printf("Exact value of b is : %dn", b
);
getch();
return 0;
}
Nested Switch Statements

Mais conteúdo relacionado

Mais procurados

While , For , Do-While Loop
While , For , Do-While LoopWhile , For , Do-While Loop
While , For , Do-While LoopAbhishek Choksi
 
FUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPTFUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPT03062679929
 
C Programming: Control Structure
C Programming: Control StructureC Programming: Control Structure
C Programming: Control StructureSokngim Sa
 
Variables in C++, data types in c++
Variables in C++, data types in c++Variables in C++, data types in c++
Variables in C++, data types in c++Neeru Mittal
 
Operator precedence and associativity
Operator precedence and associativityOperator precedence and associativity
Operator precedence and associativityDr.Sandhiya Ravi
 
Presentation on C Switch Case Statements
Presentation on C Switch Case StatementsPresentation on C Switch Case Statements
Presentation on C Switch Case StatementsDipesh Pandey
 
Operators in c programming
Operators in c programmingOperators in c programming
Operators in c programmingsavitamhaske
 
Loops and conditional statements
Loops and conditional statementsLoops and conditional statements
Loops and conditional statementsSaad Sheikh
 
structure and union
structure and unionstructure and union
structure and unionstudent
 
Conditional and control statement
Conditional and control statementConditional and control statement
Conditional and control statementnarmadhakin
 

Mais procurados (20)

Operator.ppt
Operator.pptOperator.ppt
Operator.ppt
 
User defined functions
User defined functionsUser defined functions
User defined functions
 
While , For , Do-While Loop
While , For , Do-While LoopWhile , For , Do-While Loop
While , For , Do-While Loop
 
Pointers in c++
Pointers in c++Pointers in c++
Pointers in c++
 
Storage class in C Language
Storage class in C LanguageStorage class in C Language
Storage class in C Language
 
Break and continue
Break and continueBreak and continue
Break and continue
 
FUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPTFUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPT
 
C Programming: Control Structure
C Programming: Control StructureC Programming: Control Structure
C Programming: Control Structure
 
Type conversion
Type  conversionType  conversion
Type conversion
 
Data types
Data typesData types
Data types
 
Variables in C++, data types in c++
Variables in C++, data types in c++Variables in C++, data types in c++
Variables in C++, data types in c++
 
Operator precedence and associativity
Operator precedence and associativityOperator precedence and associativity
Operator precedence and associativity
 
Presentation on C Switch Case Statements
Presentation on C Switch Case StatementsPresentation on C Switch Case Statements
Presentation on C Switch Case Statements
 
Strings
StringsStrings
Strings
 
Control statements in c
Control statements in cControl statements in c
Control statements in c
 
Operators in c programming
Operators in c programmingOperators in c programming
Operators in c programming
 
Loops and conditional statements
Loops and conditional statementsLoops and conditional statements
Loops and conditional statements
 
structure and union
structure and unionstructure and union
structure and union
 
Conditional and control statement
Conditional and control statementConditional and control statement
Conditional and control statement
 
Function in C Language
Function in C Language Function in C Language
Function in C Language
 

Destaque

Selection statements
Selection statementsSelection statements
Selection statementsHarsh Dabas
 
Control structures selection
Control structures   selectionControl structures   selection
Control structures selectionOnline
 
Control structures in C++ Programming Language
Control structures in C++ Programming LanguageControl structures in C++ Programming Language
Control structures in C++ Programming LanguageAhmad Idrees
 
The Three Basic Selection Structures in C++ Programming Concepts
The Three Basic Selection Structures in C++ Programming ConceptsThe Three Basic Selection Structures in C++ Programming Concepts
The Three Basic Selection Structures in C++ Programming ConceptsTech
 
Conditional Statements | If-then Statements
Conditional Statements | If-then StatementsConditional Statements | If-then Statements
Conditional Statements | If-then Statementssheisirenebkm
 
9. statements (conditional statements)
9. statements (conditional statements)9. statements (conditional statements)
9. statements (conditional statements)Way2itech
 
Conditional Statement in C Language
Conditional Statement in C LanguageConditional Statement in C Language
Conditional Statement in C LanguageShaina Arora
 
Switch statement, break statement, go to statement
Switch statement, break statement, go to statementSwitch statement, break statement, go to statement
Switch statement, break statement, go to statementRaj Parekh
 
The Switch Statement in java
The Switch Statement in javaThe Switch Statement in java
The Switch Statement in javaTalha Saleem
 
Presentatie Adhd En Cogmed Velsen 2011
Presentatie Adhd En Cogmed Velsen 2011Presentatie Adhd En Cogmed Velsen 2011
Presentatie Adhd En Cogmed Velsen 2011jbcmertens
 
說話的藝術
說話的藝術說話的藝術
說話的藝術qfaycho
 
Life in 1500 History Lesson 1
Life in 1500 History Lesson 1Life in 1500 History Lesson 1
Life in 1500 History Lesson 1Michael Foong
 
Nieuwe inzichten in de behandeling van ADHD
Nieuwe inzichten in de behandeling van ADHDNieuwe inzichten in de behandeling van ADHD
Nieuwe inzichten in de behandeling van ADHDlinuspauling
 
Concentratiestoornissen
ConcentratiestoornissenConcentratiestoornissen
ConcentratiestoornissenStershop BV
 
Relatie en oplossingsgericht werken (Updated Version - 2013)
Relatie  en oplossingsgericht werken (Updated Version - 2013)Relatie  en oplossingsgericht werken (Updated Version - 2013)
Relatie en oplossingsgericht werken (Updated Version - 2013)Philippe Bailleur
 

Destaque (20)

Selection statements
Selection statementsSelection statements
Selection statements
 
Control structures selection
Control structures   selectionControl structures   selection
Control structures selection
 
Control structures in C++ Programming Language
Control structures in C++ Programming LanguageControl structures in C++ Programming Language
Control structures in C++ Programming Language
 
The Three Basic Selection Structures in C++ Programming Concepts
The Three Basic Selection Structures in C++ Programming ConceptsThe Three Basic Selection Structures in C++ Programming Concepts
The Three Basic Selection Structures in C++ Programming Concepts
 
Conditional Statements | If-then Statements
Conditional Statements | If-then StatementsConditional Statements | If-then Statements
Conditional Statements | If-then Statements
 
9. statements (conditional statements)
9. statements (conditional statements)9. statements (conditional statements)
9. statements (conditional statements)
 
Conditional Statement in C Language
Conditional Statement in C LanguageConditional Statement in C Language
Conditional Statement in C Language
 
Switch statement, break statement, go to statement
Switch statement, break statement, go to statementSwitch statement, break statement, go to statement
Switch statement, break statement, go to statement
 
Flow Control (C#)
Flow Control (C#)Flow Control (C#)
Flow Control (C#)
 
The Switch Statement in java
The Switch Statement in javaThe Switch Statement in java
The Switch Statement in java
 
Iteration
IterationIteration
Iteration
 
Presentatie Adhd En Cogmed Velsen 2011
Presentatie Adhd En Cogmed Velsen 2011Presentatie Adhd En Cogmed Velsen 2011
Presentatie Adhd En Cogmed Velsen 2011
 
Seminar Time Management
Seminar Time ManagementSeminar Time Management
Seminar Time Management
 
說話的藝術
說話的藝術說話的藝術
說話的藝術
 
Life in 1500 History Lesson 1
Life in 1500 History Lesson 1Life in 1500 History Lesson 1
Life in 1500 History Lesson 1
 
National income
National incomeNational income
National income
 
Nieuwe inzichten in de behandeling van ADHD
Nieuwe inzichten in de behandeling van ADHDNieuwe inzichten in de behandeling van ADHD
Nieuwe inzichten in de behandeling van ADHD
 
Concentratiestoornissen
ConcentratiestoornissenConcentratiestoornissen
Concentratiestoornissen
 
Relatie en oplossingsgericht werken (Updated Version - 2013)
Relatie  en oplossingsgericht werken (Updated Version - 2013)Relatie  en oplossingsgericht werken (Updated Version - 2013)
Relatie en oplossingsgericht werken (Updated Version - 2013)
 
Time management
Time managementTime management
Time management
 

Semelhante a Selection Statements in C Programming

C statements.ppt presentation in c language
C statements.ppt presentation in c languageC statements.ppt presentation in c language
C statements.ppt presentation in c languagechintupro9
 
Decision statements in c language
Decision statements in c languageDecision statements in c language
Decision statements in c languagetanmaymodi4
 
Decision statements in c laguage
Decision statements in c laguageDecision statements in c laguage
Decision statements in c laguageTanmay Modi
 
Decision Making and Branching in C
Decision Making and Branching  in CDecision Making and Branching  in C
Decision Making and Branching in CRAJ KUMAR
 
C Control Statements.docx
C Control Statements.docxC Control Statements.docx
C Control Statements.docxJavvajiVenkat
 
Control Structures in C
Control Structures in CControl Structures in C
Control Structures in Csana shaikh
 
C programming decision making
C programming decision makingC programming decision making
C programming decision makingSENA
 
Flow of control C ++ By TANUJ
Flow of control C ++ By TANUJFlow of control C ++ By TANUJ
Flow of control C ++ By TANUJTANUJ ⠀
 
Control statements anil
Control statements anilControl statements anil
Control statements anilAnil Dutt
 
Java Decision Control
Java Decision ControlJava Decision Control
Java Decision ControlJayfee Ramos
 
unit 2-Control Structures.pptx
unit 2-Control Structures.pptxunit 2-Control Structures.pptx
unit 2-Control Structures.pptxishaparte4
 
C Programming - Decision making, Looping
C  Programming - Decision making, LoopingC  Programming - Decision making, Looping
C Programming - Decision making, LoopingMURALIDHAR R
 
Introduction to Selection control structures in C++
Introduction to Selection control structures in C++ Introduction to Selection control structures in C++
Introduction to Selection control structures in C++ Neeru Mittal
 
Dti2143 chap 4 control structures aka_selection
Dti2143 chap 4 control structures aka_selectionDti2143 chap 4 control structures aka_selection
Dti2143 chap 4 control structures aka_selectionalish sha
 
Dti2143 chap 4 control structures aka_selection
Dti2143 chap 4 control structures aka_selectionDti2143 chap 4 control structures aka_selection
Dti2143 chap 4 control structures aka_selectionalish sha
 

Semelhante a Selection Statements in C Programming (20)

C statements.ppt presentation in c language
C statements.ppt presentation in c languageC statements.ppt presentation in c language
C statements.ppt presentation in c language
 
Controls & Loops in C
Controls & Loops in C Controls & Loops in C
Controls & Loops in C
 
Decision statements in c language
Decision statements in c languageDecision statements in c language
Decision statements in c language
 
Decision statements in c laguage
Decision statements in c laguageDecision statements in c laguage
Decision statements in c laguage
 
CH-4 (1).pptx
CH-4 (1).pptxCH-4 (1).pptx
CH-4 (1).pptx
 
Decision Making and Branching in C
Decision Making and Branching  in CDecision Making and Branching  in C
Decision Making and Branching in C
 
Control structures in C
Control structures in CControl structures in C
Control structures in C
 
C Control Statements.docx
C Control Statements.docxC Control Statements.docx
C Control Statements.docx
 
Control Statement programming
Control Statement programmingControl Statement programming
Control Statement programming
 
Control Structures in C
Control Structures in CControl Structures in C
Control Structures in C
 
C programming decision making
C programming decision makingC programming decision making
C programming decision making
 
Flow of control C ++ By TANUJ
Flow of control C ++ By TANUJFlow of control C ++ By TANUJ
Flow of control C ++ By TANUJ
 
Control statements anil
Control statements anilControl statements anil
Control statements anil
 
Java Decision Control
Java Decision ControlJava Decision Control
Java Decision Control
 
unit 2-Control Structures.pptx
unit 2-Control Structures.pptxunit 2-Control Structures.pptx
unit 2-Control Structures.pptx
 
C Programming - Decision making, Looping
C  Programming - Decision making, LoopingC  Programming - Decision making, Looping
C Programming - Decision making, Looping
 
Introduction to Selection control structures in C++
Introduction to Selection control structures in C++ Introduction to Selection control structures in C++
Introduction to Selection control structures in C++
 
Dti2143 chap 4 control structures aka_selection
Dti2143 chap 4 control structures aka_selectionDti2143 chap 4 control structures aka_selection
Dti2143 chap 4 control structures aka_selection
 
Dti2143 chap 4 control structures aka_selection
Dti2143 chap 4 control structures aka_selectionDti2143 chap 4 control structures aka_selection
Dti2143 chap 4 control structures aka_selection
 
CONTROL STMTS.pptx
CONTROL STMTS.pptxCONTROL STMTS.pptx
CONTROL STMTS.pptx
 

Mais de Kamal Acharya

Programming the basic computer
Programming the basic computerProgramming the basic computer
Programming the basic computerKamal Acharya
 
Introduction to Computer Security
Introduction to Computer SecurityIntroduction to Computer Security
Introduction to Computer SecurityKamal Acharya
 
Making decision and repeating in PHP
Making decision and repeating  in PHPMaking decision and repeating  in PHP
Making decision and repeating in PHPKamal Acharya
 
Working with arrays in php
Working with arrays in phpWorking with arrays in php
Working with arrays in phpKamal Acharya
 
Text and Numbers (Data Types)in PHP
Text and Numbers (Data Types)in PHPText and Numbers (Data Types)in PHP
Text and Numbers (Data Types)in PHPKamal Acharya
 
Capacity Planning of Data Warehousing
Capacity Planning of Data WarehousingCapacity Planning of Data Warehousing
Capacity Planning of Data WarehousingKamal Acharya
 
Information Privacy and Data Mining
Information Privacy and Data MiningInformation Privacy and Data Mining
Information Privacy and Data MiningKamal Acharya
 
Association Analysis in Data Mining
Association Analysis in Data MiningAssociation Analysis in Data Mining
Association Analysis in Data MiningKamal Acharya
 
Classification techniques in data mining
Classification techniques in data miningClassification techniques in data mining
Classification techniques in data miningKamal Acharya
 
Introduction to Data Mining and Data Warehousing
Introduction to Data Mining and Data WarehousingIntroduction to Data Mining and Data Warehousing
Introduction to Data Mining and Data WarehousingKamal Acharya
 

Mais de Kamal Acharya (20)

Programming the basic computer
Programming the basic computerProgramming the basic computer
Programming the basic computer
 
Computer Arithmetic
Computer ArithmeticComputer Arithmetic
Computer Arithmetic
 
Introduction to Computer Security
Introduction to Computer SecurityIntroduction to Computer Security
Introduction to Computer Security
 
Session and Cookies
Session and CookiesSession and Cookies
Session and Cookies
 
Functions in php
Functions in phpFunctions in php
Functions in php
 
Web forms in php
Web forms in phpWeb forms in php
Web forms in php
 
Making decision and repeating in PHP
Making decision and repeating  in PHPMaking decision and repeating  in PHP
Making decision and repeating in PHP
 
Working with arrays in php
Working with arrays in phpWorking with arrays in php
Working with arrays in php
 
Text and Numbers (Data Types)in PHP
Text and Numbers (Data Types)in PHPText and Numbers (Data Types)in PHP
Text and Numbers (Data Types)in PHP
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
 
Capacity Planning of Data Warehousing
Capacity Planning of Data WarehousingCapacity Planning of Data Warehousing
Capacity Planning of Data Warehousing
 
Data Warehousing
Data WarehousingData Warehousing
Data Warehousing
 
Search Engines
Search EnginesSearch Engines
Search Engines
 
Web Mining
Web MiningWeb Mining
Web Mining
 
Information Privacy and Data Mining
Information Privacy and Data MiningInformation Privacy and Data Mining
Information Privacy and Data Mining
 
Cluster Analysis
Cluster AnalysisCluster Analysis
Cluster Analysis
 
Association Analysis in Data Mining
Association Analysis in Data MiningAssociation Analysis in Data Mining
Association Analysis in Data Mining
 
Classification techniques in data mining
Classification techniques in data miningClassification techniques in data mining
Classification techniques in data mining
 
Data Preprocessing
Data PreprocessingData Preprocessing
Data Preprocessing
 
Introduction to Data Mining and Data Warehousing
Introduction to Data Mining and Data WarehousingIntroduction to Data Mining and Data Warehousing
Introduction to Data Mining and Data Warehousing
 

Último

Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...PsychoTech Services
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024Janet Corral
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfAyushMahapatra5
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 

Último (20)

Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 

Selection Statements in C Programming

  • 1. LOGICAL EXPRESSIONS  IF STATEMENT SWITCH STATEMENT Selection Statements
  • 2. Flow of Control  Unless specified , the order of statement execution through a C program is linear: one statement after the other, in sequence.  Some programming statements modify that order, allowing us to:  decide whether or not to execute a particular statement, or perform a statement over and over, repetitively
  • 3. 3 Flow of Control  These decisions are based on a boolean Or logical expression (also called a condition) that evaluates to true or false  The order of statement execution is called the flow of control
  • 7. Logical Expression  Logical expression is an expression which uses one or more logical operators, e.g.,  (temperature > 90.0 && humidity > 0.90)  !(n <= 0 || n >= 100).  The output of the logical expression is the boolean value either true or false.
  • 8. If Statements  If statements consists of boolean expression followed by one or more statements.  If the boolean expression evaluates to true, the statements inside the block get executed otherwise the first statement outside the block get executed.  The false value is o and all the other values are evaluated as true in C.
  • 9. If Statement  The syntax of an If statement in C Program is given below
  • 13. If…else Statement  If statements can be followed by the optional else statements, which get executed when the boolean expression is false.
  • 17. If…elseif…else Statement  If statement can be followed by optional elseif..else statement, which is very useful to test various conditions using single if…elseif statement.  Following things should be kept in mind  An if can have zero or one else's and it must come after any else if's.  An if can have zero to many else if's and they must come before the else.  Once an else if succeeds, none of the remaining else if's or else's will be tested.
  • 19. If…elseif…else Statement(Example) #include <stdio.h> #include<conio.h> int main () { int a = 100; if( a == 10 ) { printf("Value of a is 10n" ); } else if( a == 20 ) { printf("Value of a is 20n" ); } else if( a == 30 ) { printf("Value of a is 30n" ); } else { printf("None of the values is matchingn" ); } printf("Exact value of a is: %dn", a ); getch(); return 0; }
  • 21. Nested if Statements  It is always legal in C programming to nest if-else statements, which means we can use one if or else if statement inside another if or else if statement(s).
  • 22. Nested if Statements #include <stdio.h> #include <conio.h> int main () { int a = 100; int b = 200; if( a == 100 ) { if( b == 200 ) { printf("Value of a is 100 and b is 200n" ); } } printf("Exact value of a is : %dn", a ); printf("Exact value of b is : %dn", b ); getch(); return 0; }
  • 24. Switch Statement  A switch statement allows a variable to be tested for equality against a list of values.  Each value is called a case, and the variable being switched on is checked for each switch case.  The following rules apply to a switch statement:  The expression used in a switch statement must have an integral or enumerated type, or be of a class type in which the class has a single conversion function to an integral or enumerated type.  You can have any number of case statements within a switch. Each case is followed by the value to be compared to and a colon.  The constant-expression for a case must be the same data type as the variable in the switch, and it must be a constant or a literal.
  • 25. Switch Statement  When the variable being switched on is equal to a case, the statements following that case will execute until a break statement is reached.  When a break statement is reached, the switch terminates, and the flow of control jumps to the next line following the switch statement.  Not every case needs to contain a break. If no break appears, the flow of control will fall through to subsequent cases until a break is reached.  A switch statement can have an optional default case, which must appear at the end of the switch. The default case can be used for performing a task when none of the cases is true. No break is needed in the default case.
  • 28. Switch Statement #include <stdio.h> #include <conio.h> int main () { char grade = 'B'; switch(grade) { case 'A' : printf("Excellent!n" ); break; case 'B' : case 'C' : printf("Well donen" ); break; case 'D' : printf("You passedn" ); break; case 'F' : printf("Better try againn" ); break; default : printf("Invalid graden" ); } printf("Your grade is %cn", grade ); getch(); return 0; }
  • 30. Nested Switch Statements  It is possible to have a switch as part of the statement sequence of an outer switch.  Even if the case constants of the inner and outer switch contain common values, no conflicts will arise.
  • 32. Nested Switch Statements #include <stdio.h> #include <conio.h> int main () { int a = 100; int b = 200; switch(a) { case 100: printf("This is part of outer switchn", a ); switch(b) { case 200: printf("This is part of inner switchn", a ); } } printf("Exact value of a is : %dn", a ); printf("Exact value of b is : %dn", b ); getch(); return 0; }