SlideShare a Scribd company logo
1 of 40
Unit-IV
Decision Statements
Introduction
 A program is execution of one or more instructions
sequentially in the order in which they come in to sight.
 This process is similar to reading the text that appears in
notebook.
 Quite often it is desirable in a program to alter the sequence
of the statements depending upon certain circumstances.
 Decision making statements in a programming language help
the programmer to transfer the control from one part to other
parts of the program.
Introduction (cont..)
 Decision making statements helps the programmer in
determining the flow of control.
 This involves a decision making conditions to see whether the
particular condition is satisfied or not.
Decision making statements in C
 if statement
 if –else statement
 if-else-if ladder statement
 nested if-else statement
 switch-case statement
 goto statement
if statement
 C uses the keyword if to execute a set of command lines or one command line
when logical condition is true.
void main()
{
if(expression)
{
statement1;
statement2;
}
statement3;
}
if statement (continue..)
 If statement contains an expression which is evaluated. If the expression is
true it returns 1 otherwise 0.
 In case the condition is true the compiler execute the lines within if block.
Else compiler skips the lines within if block.
 The conditional statement should not be terminated with semi-colon.
 The multiple statements which are to be executed if condition is true are
enclosed within curly bracket.
 The curly bracket indicates the scope of if statement.
if statement (continue…)
void main()
{
if(expression)
{
statement1;
statement2;
}
statement3;
}
void main()
{
if(expression)
statement1;
statement2;
}
Write a program to check whether entered number is less than 10. if
yes print the same.
void main()
{
int n;
clrscr();
printf(“enter a number”);
scanf(“%d”, &n);
if(n<10)
printf(“entered number is less than 10);
getch();
}
Start
Input
value
of n
If
n<10
Print
message
Stop
True
False
Write a program to check whether entered number is less 10 and
greater than 0. if yes print the same.
void main()
{
int n;
clrscr();
printf(“enter a number”);
scanf(“%d”, &n);
if(n<10 && n>0)
printf(“entered number is less than 10 and greater than 0);
getch();
}
Output?
main( )
{
int a = 300, b, c ;
if ( a >= 400 )
b = 300 ;
c = 200 ;
printf ( "n%d %d", b, c ) ;
}
main( )
{
int a = 300, b, c ;
if ( a >= 400 )
b = 300 ;
c = 200 ;
printf ( "n%d %d", b, c ) ;
}
if-else statement
 if block statement execute only when the condition in if is true.
 When condition is flase, program control executes the next statement
which appear after if statement.
 The if-else statement takes care of the true and false condition.
 It has two blocks. One block is for if and it is executed when the condition
is true.
 The other block is of else and it is executed when the condition is false.
 The else statement can not be used without if.
 No multiple else statements are allowed with one if
Is condition
true?
if block execution
else block execution
Next statement
Stop
NO
Yes
From previous statement
If-else
Statement
if-else statement (continue..)
void main()
{
if(expression)
{
statement1;
statement2;
}
else
{
statement3;
statement4;
}
}
if-else statement
void main()
{
if(expression)
{
statement1;
statement2;
}
else
{
statement3;
statement4;
}
}
void main()
{
if(expression)
statement1;
else
statement2;
}
Write a program to add three numbers and after addition check if sum is between of 100
and 200 or not.
void main()
{
int a,b,c,d;
clrscr();
printf(“enter three numbers a,b,c”);
scanf(“%d,%d,%d”,&a, &b, &c);
d=a+b+c;
if(d>100 && d<200)
printf(“n sum is %d which is in between 100 and 200”);
else
printf(“n sum is %d which is out of range”);
getch();
}
Output?
main( )
{
int x = 3, y = 5 ;
if ( x == 3 )
printf ( "%d", x ) ;
else
printf ( "%d", y ) ;
}
Output?
main( )
{
int i = 65 ;
char j = ‘A’ ;
if ( i == j )
printf ( “C is WOW” ) ;
else
printf( "C is a headache" ) ;
}
Find out error
void main( )
{
float a = 12.25, b = 12.52 ;
if ( a = b )
printf ( "na and b are equal" ) ;
}
Find out error
main( )
{
int x = 10 ;
if x >= 2
printf ( "n%d", x ) ;
}
Find out error
Void main( )
{
int x = 10, y = 15 ;
if ( x % 2 = y % 3 )
printf ( "Equal" ) ;
}
Nested if-else statement
if(condition)
{
if(condition)
{
statement1;
statement2;
}
else
{
statement3;
statement4;
}
}
else
{
if(condition)
{
statement5;
statement6;
}
else
{
statement7;
statement8;
}
}
Is 1st
condition
true?
Is 2nd
condition
true?
Is 3rd
condition
true?
statement4 statement3 Statement2 statement1
Next statement
True
True
True
False
False
False
From previous statement
Example
Void main()
{
Int i, age;
Printf (“enter 1 for male and 2 for female”);
Scanf(“%d”, &i);
printf(“Enter your age”);
scanf(“%d”, &age);
If(i==1)
{
if(age>20)
printf(“Eligible for marriage”);
else
printf(“Not eligible for marriage”);
If-else-if Ladder statement
 If the first logical condition is true the compiler executes block followed by
first if condition, otherwise it skips that block and checks for next logical
condition followed by else-if and if it is true the block statement followed
by that else-if will be executed.
Is 1st
condition
true?
Is 2nd
condition
true?
Is 3rd
condition
true?
Is 4th
condition
true?
STATEMENT 5
STATEMENT 3
STATEMENT 2
STATEMENT 1 STATEMENT 4
FALSE
FALSE
FALSE
FALSE
TRUE
TRUE
TRUE
TRUE
TO NEXT STATEMENT
if (condition)
{
Statement 1;
Statement 2;
}
else if(condition)
{
Statement 3;
Statement 4;
}
else
{
Statement 5;
Statement 6;
}
goto statement- Unconditional
branching
 This statement does not require any condition for jump.
 This statement passes control anywhere in program.
 Control is passed to another part of program without testing any
condition.
 goto statement can be defined as follows:
goto label;
where label name must start with character.
 The label is the position where the control is to be transferred.
goto statement (continue..)
void main()
{
int x;
clrscr();
printf(“enter a number”);
scanf(“%d”,&x);
if(x%2==0)
goto even;
else
goto odd;
even: printf(“%d is even”,x);
getch();
return;
odd: printf(“%d is odd”,x);
getch();
}
break statement
continue statement
Switch-case-default
 The control statement that allows us to make a decision from the number
of choices is called a switch,
 or more correctly a switch-case-default, since these three keywords go
together to make up the control statement.
switch ( integer expression )
{
case constant 1 :
do this ;
case constant 2 :
do this ;
case constant 3 :
do this ;
default :
do this ;
}
 The integer expression following the keyword switch is any C expression
that will yield an integer value.
 It could be an integer constant like 1, 2 or 3, or an expression that
evaluates to an integer.
 The keyword case is followed by an integer or a character constant.
 Each constant in each case must be different from all the others.
main( )
{
int i = 2 ;
switch ( i )
{
case 1 :
printf ( "I am in case 1 n" ) ;
case 2 :
printf ( "I am in case 2 n" ) ;
case 3 :
printf ( "I am in case 3 n" ) ;
default :
printf ( "I am in default n" ) ;
}
}
 If you want that only case 2 should get executed, it is upto you to get out
of the switch then and there by using a break statement.
main( )
{
int i = 2 ;
switch ( i )
{
case 1 :
printf ( "I am in case 1 n" ) ;
break ;
case 2 :
printf ( "I am in case 2 n" ) ;
break ;
case 3 :
printf ( "I am in case 3 n" ) ;
break ;
default :
printf ( "I am in default n" ) ;
}
}
SWITCH-CASE
FLOW CHART

More Related Content

Similar to CH-4 (1).pptx

Loops and conditional statements
Loops and conditional statementsLoops and conditional statements
Loops and conditional statementsSaad Sheikh
 
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
 
unit 2-Control Structures.pptx
unit 2-Control Structures.pptxunit 2-Control Structures.pptx
unit 2-Control Structures.pptxishaparte4
 
2. Control structures with for while and do while.ppt
2. Control structures with for while and do while.ppt2. Control structures with for while and do while.ppt
2. Control structures with for while and do while.pptManojKhadilkar1
 
Control and conditional statements
Control and conditional statementsControl and conditional statements
Control and conditional statementsrajshreemuthiah
 
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
 
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
 
Fundamental of Information Technology - UNIT 8
Fundamental of Information Technology - UNIT 8Fundamental of Information Technology - UNIT 8
Fundamental of Information Technology - UNIT 8Shipra Swati
 
Control Structures
Control StructuresControl Structures
Control StructuresGhaffar Khan
 
1. Control Structure in C.pdf
1. Control Structure in C.pdf1. Control Structure in C.pdf
1. Control Structure in C.pdfRanjeetaSharma8
 
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
 

Similar to CH-4 (1).pptx (20)

Loops and conditional statements
Loops and conditional statementsLoops and conditional statements
Loops and conditional statements
 
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
 
ICP - Lecture 7 and 8
ICP - Lecture 7 and 8ICP - Lecture 7 and 8
ICP - Lecture 7 and 8
 
unit 2-Control Structures.pptx
unit 2-Control Structures.pptxunit 2-Control Structures.pptx
unit 2-Control Structures.pptx
 
Control Statement programming
Control Statement programmingControl Statement programming
Control Statement programming
 
2. Control structures with for while and do while.ppt
2. Control structures with for while and do while.ppt2. Control structures with for while and do while.ppt
2. Control structures with for while and do while.ppt
 
Control and conditional statements
Control and conditional statementsControl and conditional statements
Control and conditional statements
 
Decision Making and Branching
Decision Making and BranchingDecision Making and Branching
Decision Making and Branching
 
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++
 
control statement
control statement control statement
control statement
 
computer programming Control Statements.pptx
computer programming Control Statements.pptxcomputer programming Control Statements.pptx
computer programming Control Statements.pptx
 
C PROGRAMMING p-3.pptx
C PROGRAMMING p-3.pptxC PROGRAMMING p-3.pptx
C PROGRAMMING p-3.pptx
 
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
 
Fundamental of Information Technology - UNIT 8
Fundamental of Information Technology - UNIT 8Fundamental of Information Technology - UNIT 8
Fundamental of Information Technology - UNIT 8
 
Decision Making.pptx
Decision Making.pptxDecision Making.pptx
Decision Making.pptx
 
Control Structures
Control StructuresControl Structures
Control Structures
 
1. Control Structure in C.pdf
1. Control Structure in C.pdf1. Control Structure in C.pdf
1. Control Structure in C.pdf
 
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
 
Control structures in c
Control structures in cControl structures in c
Control structures in c
 

Recently uploaded

HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2RajaP95
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.eptoze12
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024hassan khalil
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxDeepakSakkari2
 
Introduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxIntroduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxvipinkmenon1
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024Mark Billinghurst
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130Suhani Kapoor
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ
 
Churning of Butter, Factors affecting .
Churning of Butter, Factors affecting  .Churning of Butter, Factors affecting  .
Churning of Butter, Factors affecting .Satyam Kumar
 
Current Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLCurrent Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLDeelipZope
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxPoojaBan
 
complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...asadnawaz62
 
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
 
power system scada applications and uses
power system scada applications and usespower system scada applications and uses
power system scada applications and usesDevarapalliHaritha
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfAsst.prof M.Gokilavani
 

Recently uploaded (20)

HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2
 
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Serviceyoung call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptx
 
Introduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxIntroduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptx
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
 
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
 
Churning of Butter, Factors affecting .
Churning of Butter, Factors affecting  .Churning of Butter, Factors affecting  .
Churning of Butter, Factors affecting .
 
Current Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLCurrent Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCL
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptx
 
complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...
 
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
 
power system scada applications and uses
power system scada applications and usespower system scada applications and uses
power system scada applications and uses
 
young call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Serviceyoung call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Service
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
 
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
 

CH-4 (1).pptx

  • 2. Introduction  A program is execution of one or more instructions sequentially in the order in which they come in to sight.  This process is similar to reading the text that appears in notebook.  Quite often it is desirable in a program to alter the sequence of the statements depending upon certain circumstances.  Decision making statements in a programming language help the programmer to transfer the control from one part to other parts of the program.
  • 3. Introduction (cont..)  Decision making statements helps the programmer in determining the flow of control.  This involves a decision making conditions to see whether the particular condition is satisfied or not.
  • 4. Decision making statements in C  if statement  if –else statement  if-else-if ladder statement  nested if-else statement  switch-case statement  goto statement
  • 5. if statement  C uses the keyword if to execute a set of command lines or one command line when logical condition is true. void main() { if(expression) { statement1; statement2; } statement3; }
  • 6. if statement (continue..)  If statement contains an expression which is evaluated. If the expression is true it returns 1 otherwise 0.  In case the condition is true the compiler execute the lines within if block. Else compiler skips the lines within if block.  The conditional statement should not be terminated with semi-colon.  The multiple statements which are to be executed if condition is true are enclosed within curly bracket.  The curly bracket indicates the scope of if statement.
  • 7. if statement (continue…) void main() { if(expression) { statement1; statement2; } statement3; } void main() { if(expression) statement1; statement2; }
  • 8. Write a program to check whether entered number is less than 10. if yes print the same. void main() { int n; clrscr(); printf(“enter a number”); scanf(“%d”, &n); if(n<10) printf(“entered number is less than 10); getch(); }
  • 10. Write a program to check whether entered number is less 10 and greater than 0. if yes print the same. void main() { int n; clrscr(); printf(“enter a number”); scanf(“%d”, &n); if(n<10 && n>0) printf(“entered number is less than 10 and greater than 0); getch(); }
  • 11. Output? main( ) { int a = 300, b, c ; if ( a >= 400 ) b = 300 ; c = 200 ; printf ( "n%d %d", b, c ) ; } main( ) { int a = 300, b, c ; if ( a >= 400 ) b = 300 ; c = 200 ; printf ( "n%d %d", b, c ) ; }
  • 12. if-else statement  if block statement execute only when the condition in if is true.  When condition is flase, program control executes the next statement which appear after if statement.  The if-else statement takes care of the true and false condition.  It has two blocks. One block is for if and it is executed when the condition is true.  The other block is of else and it is executed when the condition is false.  The else statement can not be used without if.  No multiple else statements are allowed with one if
  • 13. Is condition true? if block execution else block execution Next statement Stop NO Yes From previous statement If-else Statement
  • 14. if-else statement (continue..) void main() { if(expression) { statement1; statement2; } else { statement3; statement4; } }
  • 16. Write a program to add three numbers and after addition check if sum is between of 100 and 200 or not. void main() { int a,b,c,d; clrscr(); printf(“enter three numbers a,b,c”); scanf(“%d,%d,%d”,&a, &b, &c); d=a+b+c; if(d>100 && d<200) printf(“n sum is %d which is in between 100 and 200”); else printf(“n sum is %d which is out of range”); getch(); }
  • 17. Output? main( ) { int x = 3, y = 5 ; if ( x == 3 ) printf ( "%d", x ) ; else printf ( "%d", y ) ; }
  • 18. Output? main( ) { int i = 65 ; char j = ‘A’ ; if ( i == j ) printf ( “C is WOW” ) ; else printf( "C is a headache" ) ; }
  • 19. Find out error void main( ) { float a = 12.25, b = 12.52 ; if ( a = b ) printf ( "na and b are equal" ) ; }
  • 20. Find out error main( ) { int x = 10 ; if x >= 2 printf ( "n%d", x ) ; }
  • 21. Find out error Void main( ) { int x = 10, y = 15 ; if ( x % 2 = y % 3 ) printf ( "Equal" ) ; }
  • 24. Is 1st condition true? Is 2nd condition true? Is 3rd condition true? statement4 statement3 Statement2 statement1 Next statement True True True False False False From previous statement
  • 25. Example Void main() { Int i, age; Printf (“enter 1 for male and 2 for female”); Scanf(“%d”, &i); printf(“Enter your age”); scanf(“%d”, &age); If(i==1) { if(age>20) printf(“Eligible for marriage”); else printf(“Not eligible for marriage”);
  • 26. If-else-if Ladder statement  If the first logical condition is true the compiler executes block followed by first if condition, otherwise it skips that block and checks for next logical condition followed by else-if and if it is true the block statement followed by that else-if will be executed.
  • 27. Is 1st condition true? Is 2nd condition true? Is 3rd condition true? Is 4th condition true? STATEMENT 5 STATEMENT 3 STATEMENT 2 STATEMENT 1 STATEMENT 4 FALSE FALSE FALSE FALSE TRUE TRUE TRUE TRUE TO NEXT STATEMENT
  • 28. if (condition) { Statement 1; Statement 2; } else if(condition) { Statement 3; Statement 4; } else { Statement 5; Statement 6; }
  • 29. goto statement- Unconditional branching  This statement does not require any condition for jump.  This statement passes control anywhere in program.  Control is passed to another part of program without testing any condition.  goto statement can be defined as follows: goto label; where label name must start with character.  The label is the position where the control is to be transferred.
  • 30. goto statement (continue..) void main() { int x; clrscr(); printf(“enter a number”); scanf(“%d”,&x); if(x%2==0) goto even; else goto odd;
  • 31. even: printf(“%d is even”,x); getch(); return; odd: printf(“%d is odd”,x); getch(); }
  • 34. Switch-case-default  The control statement that allows us to make a decision from the number of choices is called a switch,  or more correctly a switch-case-default, since these three keywords go together to make up the control statement.
  • 35. switch ( integer expression ) { case constant 1 : do this ; case constant 2 : do this ; case constant 3 : do this ; default : do this ; }
  • 36.  The integer expression following the keyword switch is any C expression that will yield an integer value.  It could be an integer constant like 1, 2 or 3, or an expression that evaluates to an integer.  The keyword case is followed by an integer or a character constant.  Each constant in each case must be different from all the others.
  • 37. main( ) { int i = 2 ; switch ( i ) { case 1 : printf ( "I am in case 1 n" ) ; case 2 : printf ( "I am in case 2 n" ) ; case 3 : printf ( "I am in case 3 n" ) ; default : printf ( "I am in default n" ) ; } }
  • 38.  If you want that only case 2 should get executed, it is upto you to get out of the switch then and there by using a break statement.
  • 39. main( ) { int i = 2 ; switch ( i ) { case 1 : printf ( "I am in case 1 n" ) ; break ; case 2 : printf ( "I am in case 2 n" ) ; break ; case 3 : printf ( "I am in case 3 n" ) ; break ; default : printf ( "I am in default n" ) ; } }