SlideShare a Scribd company logo
1 of 27
1 . I F S T A T E M E N T
2 . S W I T C H S T A T E M E N T
3 . C O N D I T I O N A L O P E R A T O R S T A T E M E N T
4 . G O T O S T A T E M E N T
Decision Making & Branching
TYPES OF IF STATEMET
The if statement is implemented indifferent
forms depending on the complexity of
conditions to betested:
• Simple if statement
• if…..elsestatement
• Nested if…..else statement
• Else if ladder
SIMPLE IF STATEMENT
if(test-expression)
{
statement-block;
}
Statement-x;
Test
expression?
Entry
False
True
FLOW CHART OF SIMPLE IF
Statemet - Block
Entry
True
Test expression?
False
Statement-x
Next Statement
W.A.P to display a number if user enters negative number
If user enters positive number, that number won't be
displayed
intmain()
{
int number;
printf("Enter an integer:");
scanf("%d", &number);
// Testexpression is true if number is less than 0
if (number < 0)
{
printf("You entered %d.n", number);
}
printf(“Enter positive number.");
return0;
}
Output1
Enter an integer:-2
You entered -2.
Enter Positive number
W.A.P to check whether 2 nos
are equal
IF – ELSE STATEMENT
The if….elsestatement isan extensionof the simple if statement.
The general formis:
if(test-expression)
{
True-block statement(s);
}
else
{
False-block statement(s);
}
Statement-x;
FLOWCHART OF IF - ELSE
True-Block Statements
Entry
Test expression?
TrueFalse
Statement-x
Next Statement
False-Block Statements
W.A.P to check whether 2 nos
are equal or not
W.A.P whether given num is
even or odd
W.A.P to check whether person
is eligible for voting or not
Program to check number is
divisible by 5 and 11
int main()
{
int num;
/* Reads number from user */
printf("Enter any number: ");
scanf("%d", &num);
if((num % 5 == 0) && (num % 11 == 0))
{
printf("Number is divisible by 5 and 11");
}
else
{
printf("Number is not divisible by 5 and 11");
}
return 0;
}
Program to find maximum of 2 nos
intmain()
{
int num1, num2; printf("Enter two
numbers:");
scanf("%d%d", &num1, &num2);
if(num1 > num2)
{
// True part means num1 >num2
printf("%d is maximum", num1);
}
else
{
// False part means num1 <num2
printf("%d is maximum", num2);
}
return0;
}
NESTED IF - ELSE
if(test condition 1)
{
if(test condition 2)
{
statement-1;
}
else
{
statement-2;
}
}
else
{
statement-3;
}
Statement-x;
FLOW CHART OF NESTED IF - ELSE
Test condition 1?
Entry
True
False
Statement-3
Test condition 2?
Statement-1
Statement-x
Next Statement
Statement-2
TrueFalse
W.A.P to check whether two
numbers are >,<,= or !=
int var1, var2;
printf("Input the value of var1:");
scanf("%d", &var1);
printf("Input the value of var2:");
scanf("%d",&var2);
if (var1 !=var2)
{
printf("var1 is not equal to var2");
//Below – if-else is nested inside another if block
if (var1 >var2)
{
printf("var1 is greater than var2");
}
else
{
printf("var2 is greater than var1");
}
}
else
{
printf("var1 is equal to var2");
}
W.A.P to find maximum of 3 nos
int main()
{
int num1, num2, num3, maximum;
printf("Enter three numbers: ");
scanf("%d%d%d", &num1, &num2, &num3);
if(num1 > num2)
{
if(num1 > num3)
{
maximum = num1;
}
else
{
maximum = num3;
}
}
else
{
if(num2 > num3)
{
maximum = num2;
}
else
{
maximum = num3;
}
}
printf("Maximum among all three
numbers = %d", maximum);
return 0;
}
W.A.P to read three values from keyboard and print out the largest of them without using
if statement.
void main()
{
int x,y,z;
clrscr();
printf("Enter Three Numbers:--n");
scanf("%d %d %d",&x,&y,&z);
((x>y)&&(x>z))?printf("Largest is x :--
%d",x):((y>x)&&(y>z))?printf("Largest is y :-- %d",y):printf("Largest is z :-- %d",z);
}
Output:--
Enter Three Numbers:--
3 4 5
Largest is z :-- 5
ELSE – IF LADDER
if (test condition 1)
{ statement –1 ; }
elseif (test condition 2)
{ statement –2 ; }
elseif (test condition 3)
{ statement – 3 ; }
-------------
elseif (test condition n)
{ statement – n ; }
else
{ default-statement; }
Statement – x;
FLOWCHART OF ELSE-IF LADDER
Condition-2
Condition-n
Statement-1
Statement-2
Statement-n
Default-statement
Statement-x
True
True
True False
Condition-1
False
False
Program to check whether 2 nos are
=,<,>,!=main(){
int var1,var2;
printf("Input the value ofvar1:");
scanf("%d", &var1);
printf("Input the value ofvar2:");
scanf("%d",&var2);
if (var1 ==var2)
{
printf("var1 is equal tovar2");
}
else if (var1 >var2)
{
printf("var1 is greater thanvar2");
}
else if (var2 > var1)
{
printf("var2 is greater thanvar1");
}
else
{
printf("var1 is not equal tovar2");
}}
Write a C program to check whether given character is a digit,
lowercase alphabet or an uppercase alphabet.
void main()
{
charch;
clrscr();
printf("Enter the character:");
scanf("%c",&ch);
if((ch>='0')&&(ch<='9'))
printf("the number is %cdigit",ch);
else if((ch>='a')&&(ch<='z'))
printf("the character is %clowercase",ch);
else if((ch>='A')&&(ch<='Z'))
printf("the character is %cuppercase",ch);
else
printf("thecharacter is %cothertype");
getch();
}
Output:
Enter the character:7
the number is 7 digit
Enter thecharacter:R
the character is Ruppercase
SWITCH STATEMENT
Switch ( expression ) //expression is any integerexpression orcharacters
{
case value-1 : //valuesare constantsorconstantexpressionsevaluableto an integral constant
block-1;
break;
case value-2 :
default:
block-2;
break;
//default is optional..executed when nocasevalue matches
default-block;
break;
}
Statement-x;
Implement a Calculator using Switch Case
void main()
{
int a, b, c, d, e, f, ch;
printf("Enter the first no. :");
scanf("%d", &a);
printf("Enter the second no. :");
scanf("%d", &b);
printf("Enterthechoiceas n 1.Addn 2.Sub
n 3.Multiplyn 4.Dividen");
scanf("%d", &ch);
switch(ch)
{
case1:
c=a+b;
printf("%d",c);
break;
case2:
d=a-b;
printf("%d",d);
break;
case 3:
e=a*b;
printf("%d", e);
break;
case 4:
f=a/b;
printf("%d", f);
break;
default:
printf("Wrong Input");
break;
}
getch();
}
Program to find number of days in a month using switch case
int main()
{
int month;
printf("Enter month number(1-12): ");
scanf("%d", &month);
switch(month)
{
case1:
case3:
case5:
case7:
case8:
case10:
case 12: printf("31days");
break;
case 4:
case 6:
case 9:
case 11: printf("30 days");
break;
case 2: printf("28/29 days");
break;
default: printf("Invalid input! Please enter
month number between 1-12");
}
return 0;
}
GOTO STATEMENT
If you want to jumpsome wherewithoutchecking
any condition thengoto is used.
statements;
gotolabel1;
Statements;
lable1 :
statements;
statements;
label1 :
statements;
goto label1;
Statements;
GoTo Example
intmain()
{
intage;
Vote:
printf("you are eligible forvoting");
NoVote:
printf("you are not eligibletovote");
printf("Enter yourage:");
scanf("%d", &age);
if(age>=18)
gotoVote;
else
gotoNoVote;
return 0;
}
Output:
Enter your age: 23
you are eligible for voting
Enter your age: 15
you are not eligible to vote

More Related Content

What's hot

Types of loops in c language
Types of loops in c languageTypes of loops in c language
Types of loops in c languagesneha2494
 
Decision making statements in C programming
Decision making statements in C programmingDecision making statements in C programming
Decision making statements in C programmingRabin BK
 
Control structure of c
Control structure of cControl structure of c
Control structure of cKomal Kotak
 
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 Programming: Control Structure
C Programming: Control StructureC Programming: Control Structure
C Programming: Control StructureSokngim Sa
 
10. switch case
10. switch case10. switch case
10. switch caseWay2itech
 
Unit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in CUnit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in CSowmya Jyothi
 
Loops in c programming
Loops in c programmingLoops in c programming
Loops in c programmingCHANDAN KUMAR
 
Control structures in c++
Control structures in c++Control structures in c++
Control structures in c++Nitin Jawla
 
Switch Case in C Programming
Switch Case in C ProgrammingSwitch Case in C Programming
Switch Case in C ProgrammingSonya Akter Rupa
 
java programming- control statements
 java programming- control statements java programming- control statements
java programming- control statementsjyoti_lakhani
 
Control structure C++
Control structure C++Control structure C++
Control structure C++Anil Kumar
 
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
 
Conditional Statement in C#
Conditional Statement in C#Conditional Statement in C#
Conditional Statement in C#Simplilearn
 
Control statements
Control statementsControl statements
Control statementsraksharao
 

What's hot (20)

Types of loops in c language
Types of loops in c languageTypes of loops in c language
Types of loops in c language
 
Decision making statements in C programming
Decision making statements in C programmingDecision making statements in C programming
Decision making statements in C programming
 
Control structure of c
Control structure of cControl structure of c
Control structure of c
 
Decision Making and Looping
Decision Making and LoopingDecision Making and Looping
Decision Making and Looping
 
Decision Making and Branching in C
Decision Making and Branching  in CDecision Making and Branching  in C
Decision Making and Branching in C
 
C Programming: Control Structure
C Programming: Control StructureC Programming: Control Structure
C Programming: Control Structure
 
10. switch case
10. switch case10. switch case
10. switch case
 
Unit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in CUnit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in C
 
Loops in c programming
Loops in c programmingLoops in c programming
Loops in c programming
 
Control structures in c++
Control structures in c++Control structures in c++
Control structures in c++
 
Switch Case in C Programming
Switch Case in C ProgrammingSwitch Case in C Programming
Switch Case in C Programming
 
Control statements in c
Control statements in cControl statements in c
Control statements in c
 
java programming- control statements
 java programming- control statements java programming- control statements
java programming- control statements
 
Control structure C++
Control structure C++Control structure C++
Control structure C++
 
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
 
Switch case in C++
Switch case in C++Switch case in C++
Switch case in C++
 
C if else
C if elseC if else
C if else
 
Conditional Statement in C#
Conditional Statement in C#Conditional Statement in C#
Conditional Statement in C#
 
Operators in java
Operators in javaOperators in java
Operators in java
 
Control statements
Control statementsControl statements
Control statements
 

Similar to Decision making and branching in c programming

Simple if else statement,nesting of if else statement &amp; else if ladder
Simple if else statement,nesting of if else statement &amp; else if ladderSimple if else statement,nesting of if else statement &amp; else if ladder
Simple if else statement,nesting of if else statement &amp; else if ladderMoni Adhikary
 
unit 2-Control Structures.pptx
unit 2-Control Structures.pptxunit 2-Control Structures.pptx
unit 2-Control Structures.pptxishaparte4
 
CONTROLSTRUCTURES.ppt
CONTROLSTRUCTURES.pptCONTROLSTRUCTURES.ppt
CONTROLSTRUCTURES.pptSanjjaayyy
 
Control statements-Computer programming
Control statements-Computer programmingControl statements-Computer programming
Control statements-Computer programmingnmahi96
 
computer programming Control Statements.pptx
computer programming Control Statements.pptxcomputer programming Control Statements.pptx
computer programming Control Statements.pptxeaglesniper008
 
3-Conditional-if-else-switch btech computer in c.pdf
3-Conditional-if-else-switch btech computer in c.pdf3-Conditional-if-else-switch btech computer in c.pdf
3-Conditional-if-else-switch btech computer in c.pdfArkSingh7
 
Selection & Making Decisions in c
Selection & Making Decisions in cSelection & Making Decisions in c
Selection & Making Decisions in cyndaravind
 
Conditional statements
Conditional statementsConditional statements
Conditional statementsNabishaAK
 
C programming Control Structure.pptx
C programming Control Structure.pptxC programming Control Structure.pptx
C programming Control Structure.pptxDEEPAK948083
 
Control Structures in C
Control Structures in CControl Structures in C
Control Structures in Csana shaikh
 
Programming fundamental 02
Programming fundamental 02Programming fundamental 02
Programming fundamental 02Suhail Akraam
 
Nesting of if else statement & Else If Ladder
Nesting of if else statement & Else If Ladder Nesting of if else statement & Else If Ladder
Nesting of if else statement & Else If Ladder Vishvesh Jasani
 
E1 – FundamentalsPlease refer to announcements for details about.docx
E1 – FundamentalsPlease refer to announcements for details about.docxE1 – FundamentalsPlease refer to announcements for details about.docx
E1 – FundamentalsPlease refer to announcements for details about.docxjacksnathalie
 
Branching statements
Branching statementsBranching statements
Branching statementsArunMK17
 
Dti2143 chap 4 control statement part 2
Dti2143 chap 4 control statement part 2Dti2143 chap 4 control statement part 2
Dti2143 chap 4 control statement part 2alish sha
 

Similar to Decision making and branching in c programming (20)

Simple if else statement,nesting of if else statement &amp; else if ladder
Simple if else statement,nesting of if else statement &amp; else if ladderSimple if else statement,nesting of if else statement &amp; else if ladder
Simple if else statement,nesting of if else statement &amp; else if ladder
 
Decision Making and Branching
Decision Making and BranchingDecision Making and Branching
Decision Making and Branching
 
unit 2-Control Structures.pptx
unit 2-Control Structures.pptxunit 2-Control Structures.pptx
unit 2-Control Structures.pptx
 
CONTROLSTRUCTURES.ppt
CONTROLSTRUCTURES.pptCONTROLSTRUCTURES.ppt
CONTROLSTRUCTURES.ppt
 
Control statements-Computer programming
Control statements-Computer programmingControl statements-Computer programming
Control statements-Computer programming
 
SPL 7 | Conditional Statements in C
SPL 7 | Conditional Statements in CSPL 7 | Conditional Statements in C
SPL 7 | Conditional Statements in C
 
computer programming Control Statements.pptx
computer programming Control Statements.pptxcomputer programming Control Statements.pptx
computer programming Control Statements.pptx
 
175035 cse lab-03
175035 cse lab-03175035 cse lab-03
175035 cse lab-03
 
3-Conditional-if-else-switch btech computer in c.pdf
3-Conditional-if-else-switch btech computer in c.pdf3-Conditional-if-else-switch btech computer in c.pdf
3-Conditional-if-else-switch btech computer in c.pdf
 
Selection & Making Decisions in c
Selection & Making Decisions in cSelection & Making Decisions in c
Selection & Making Decisions in c
 
Conditional statements
Conditional statementsConditional statements
Conditional statements
 
C programming Control Structure.pptx
C programming Control Structure.pptxC programming Control Structure.pptx
C programming Control Structure.pptx
 
Control Structures in C
Control Structures in CControl Structures in C
Control Structures in C
 
Programming fundamental 02
Programming fundamental 02Programming fundamental 02
Programming fundamental 02
 
CH-4 (1).pptx
CH-4 (1).pptxCH-4 (1).pptx
CH-4 (1).pptx
 
Nesting of if else statement & Else If Ladder
Nesting of if else statement & Else If Ladder Nesting of if else statement & Else If Ladder
Nesting of if else statement & Else If Ladder
 
E1 – FundamentalsPlease refer to announcements for details about.docx
E1 – FundamentalsPlease refer to announcements for details about.docxE1 – FundamentalsPlease refer to announcements for details about.docx
E1 – FundamentalsPlease refer to announcements for details about.docx
 
L3 control
L3 controlL3 control
L3 control
 
Branching statements
Branching statementsBranching statements
Branching statements
 
Dti2143 chap 4 control statement part 2
Dti2143 chap 4 control statement part 2Dti2143 chap 4 control statement part 2
Dti2143 chap 4 control statement part 2
 

More from Priyansh Thakar

More from Priyansh Thakar (6)

Contributor Personality Development
Contributor Personality DevelopmentContributor Personality Development
Contributor Personality Development
 
Data convertors
Data convertorsData convertors
Data convertors
 
Scales
ScalesScales
Scales
 
Power factor and its importance
Power factor and its importancePower factor and its importance
Power factor and its importance
 
Energy storage devices
Energy storage devicesEnergy storage devices
Energy storage devices
 
Nods : Signal and Meaning
Nods : Signal and MeaningNods : Signal and Meaning
Nods : Signal and Meaning
 

Recently uploaded

Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxupamatechverse
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations120cr0395
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)Suman Mia
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile servicerehmti665
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Christo Ananth
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSCAESB
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidNikhilNagaraju
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learningmisbanausheenparvam
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escortsranjana rawat
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escortsranjana rawat
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxupamatechverse
 
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxthe ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxhumanexperienceaaa
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Serviceranjana rawat
 

Recently uploaded (20)

Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptx
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations
 
Roadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and RoutesRoadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and Routes
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile service
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentation
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfid
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learning
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptx
 
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxthe ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
 
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptxExploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
 

Decision making and branching in c programming

  • 1. 1 . I F S T A T E M E N T 2 . S W I T C H S T A T E M E N T 3 . C O N D I T I O N A L O P E R A T O R S T A T E M E N T 4 . G O T O S T A T E M E N T Decision Making & Branching
  • 2. TYPES OF IF STATEMET The if statement is implemented indifferent forms depending on the complexity of conditions to betested: • Simple if statement • if…..elsestatement • Nested if…..else statement • Else if ladder
  • 4. FLOW CHART OF SIMPLE IF Statemet - Block Entry True Test expression? False Statement-x Next Statement
  • 5. W.A.P to display a number if user enters negative number If user enters positive number, that number won't be displayed intmain() { int number; printf("Enter an integer:"); scanf("%d", &number); // Testexpression is true if number is less than 0 if (number < 0) { printf("You entered %d.n", number); } printf(“Enter positive number."); return0; } Output1 Enter an integer:-2 You entered -2. Enter Positive number
  • 6. W.A.P to check whether 2 nos are equal
  • 7. IF – ELSE STATEMENT The if….elsestatement isan extensionof the simple if statement. The general formis: if(test-expression) { True-block statement(s); } else { False-block statement(s); } Statement-x;
  • 8. FLOWCHART OF IF - ELSE True-Block Statements Entry Test expression? TrueFalse Statement-x Next Statement False-Block Statements
  • 9. W.A.P to check whether 2 nos are equal or not
  • 10. W.A.P whether given num is even or odd
  • 11. W.A.P to check whether person is eligible for voting or not
  • 12. Program to check number is divisible by 5 and 11 int main() { int num; /* Reads number from user */ printf("Enter any number: "); scanf("%d", &num); if((num % 5 == 0) && (num % 11 == 0)) { printf("Number is divisible by 5 and 11"); } else { printf("Number is not divisible by 5 and 11"); } return 0; }
  • 13. Program to find maximum of 2 nos intmain() { int num1, num2; printf("Enter two numbers:"); scanf("%d%d", &num1, &num2); if(num1 > num2) { // True part means num1 >num2 printf("%d is maximum", num1); } else { // False part means num1 <num2 printf("%d is maximum", num2); } return0; }
  • 14. NESTED IF - ELSE if(test condition 1) { if(test condition 2) { statement-1; } else { statement-2; } } else { statement-3; } Statement-x;
  • 15. FLOW CHART OF NESTED IF - ELSE Test condition 1? Entry True False Statement-3 Test condition 2? Statement-1 Statement-x Next Statement Statement-2 TrueFalse
  • 16. W.A.P to check whether two numbers are >,<,= or != int var1, var2; printf("Input the value of var1:"); scanf("%d", &var1); printf("Input the value of var2:"); scanf("%d",&var2); if (var1 !=var2) { printf("var1 is not equal to var2"); //Below – if-else is nested inside another if block if (var1 >var2) { printf("var1 is greater than var2"); } else { printf("var2 is greater than var1"); } } else { printf("var1 is equal to var2"); }
  • 17. W.A.P to find maximum of 3 nos int main() { int num1, num2, num3, maximum; printf("Enter three numbers: "); scanf("%d%d%d", &num1, &num2, &num3); if(num1 > num2) { if(num1 > num3) { maximum = num1; } else { maximum = num3; } } else { if(num2 > num3) { maximum = num2; } else { maximum = num3; } } printf("Maximum among all three numbers = %d", maximum); return 0; }
  • 18. W.A.P to read three values from keyboard and print out the largest of them without using if statement. void main() { int x,y,z; clrscr(); printf("Enter Three Numbers:--n"); scanf("%d %d %d",&x,&y,&z); ((x>y)&&(x>z))?printf("Largest is x :-- %d",x):((y>x)&&(y>z))?printf("Largest is y :-- %d",y):printf("Largest is z :-- %d",z); } Output:-- Enter Three Numbers:-- 3 4 5 Largest is z :-- 5
  • 19. ELSE – IF LADDER if (test condition 1) { statement –1 ; } elseif (test condition 2) { statement –2 ; } elseif (test condition 3) { statement – 3 ; } ------------- elseif (test condition n) { statement – n ; } else { default-statement; } Statement – x;
  • 20. FLOWCHART OF ELSE-IF LADDER Condition-2 Condition-n Statement-1 Statement-2 Statement-n Default-statement Statement-x True True True False Condition-1 False False
  • 21. Program to check whether 2 nos are =,<,>,!=main(){ int var1,var2; printf("Input the value ofvar1:"); scanf("%d", &var1); printf("Input the value ofvar2:"); scanf("%d",&var2); if (var1 ==var2) { printf("var1 is equal tovar2"); } else if (var1 >var2) { printf("var1 is greater thanvar2"); } else if (var2 > var1) { printf("var2 is greater thanvar1"); } else { printf("var1 is not equal tovar2"); }}
  • 22. Write a C program to check whether given character is a digit, lowercase alphabet or an uppercase alphabet. void main() { charch; clrscr(); printf("Enter the character:"); scanf("%c",&ch); if((ch>='0')&&(ch<='9')) printf("the number is %cdigit",ch); else if((ch>='a')&&(ch<='z')) printf("the character is %clowercase",ch); else if((ch>='A')&&(ch<='Z')) printf("the character is %cuppercase",ch); else printf("thecharacter is %cothertype"); getch(); } Output: Enter the character:7 the number is 7 digit Enter thecharacter:R the character is Ruppercase
  • 23. SWITCH STATEMENT Switch ( expression ) //expression is any integerexpression orcharacters { case value-1 : //valuesare constantsorconstantexpressionsevaluableto an integral constant block-1; break; case value-2 : default: block-2; break; //default is optional..executed when nocasevalue matches default-block; break; } Statement-x;
  • 24. Implement a Calculator using Switch Case void main() { int a, b, c, d, e, f, ch; printf("Enter the first no. :"); scanf("%d", &a); printf("Enter the second no. :"); scanf("%d", &b); printf("Enterthechoiceas n 1.Addn 2.Sub n 3.Multiplyn 4.Dividen"); scanf("%d", &ch); switch(ch) { case1: c=a+b; printf("%d",c); break; case2: d=a-b; printf("%d",d); break; case 3: e=a*b; printf("%d", e); break; case 4: f=a/b; printf("%d", f); break; default: printf("Wrong Input"); break; } getch(); }
  • 25. Program to find number of days in a month using switch case int main() { int month; printf("Enter month number(1-12): "); scanf("%d", &month); switch(month) { case1: case3: case5: case7: case8: case10: case 12: printf("31days"); break; case 4: case 6: case 9: case 11: printf("30 days"); break; case 2: printf("28/29 days"); break; default: printf("Invalid input! Please enter month number between 1-12"); } return 0; }
  • 26. GOTO STATEMENT If you want to jumpsome wherewithoutchecking any condition thengoto is used. statements; gotolabel1; Statements; lable1 : statements; statements; label1 : statements; goto label1; Statements;
  • 27. GoTo Example intmain() { intage; Vote: printf("you are eligible forvoting"); NoVote: printf("you are not eligibletovote"); printf("Enter yourage:"); scanf("%d", &age); if(age>=18) gotoVote; else gotoNoVote; return 0; } Output: Enter your age: 23 you are eligible for voting Enter your age: 15 you are not eligible to vote