SlideShare a Scribd company logo
1 of 21
PAPER NAME :CONDITIONAL
STATEMENTS.
STAFF :D.SARITHA
CLASS :I
SEMESTER :I
UNIT :I
TOPIC :PROGRAMMING IN
C
Conditional
statements
Forms of if statement
Simple if statement.
If…else statement.
Nested if…else statement.
Else .. if ladder.
IF STATEMENT
If statement is the decision making statement.
General form:
If (test expression)
{
statement – block;
}
statement-x;
IF STATEMENTS
EXAMPLE PROGRAM :
Main()
{
int a,b,c,d;
float ratio;
Printf(“Enter four integer valuesn”);
Scanf(“%d,%d,%d,%d”,&a,&b,&c,&d);
If(c-d !=0) /*execute statement block*/
{
ratio = (float)(a+b)/(float)(c-d);
printf(“ratio =%fn”,ratio);
}
}
OUTPUT:
Enter four integer values
12 23 34 45
ratio=-3.181818.
IF… ELSE STATEMENTS
If … else statement is the extension of if statement.
General form:
If (test expression)
{
//statement (s)
}
else
{
//statement(s)
}
IF ELSE STATEMENTS
EXAMPLE PROGRAM:
#include <stdio.h>
int main()
{
int number;
printf("Enter an integer: ");
scanf("%d",&number);
// True if remainder is 0
if( number%2 == 0 )
printf("%d is an even integer.",number);
else
printf("%d is an odd integer.",number);
return 0;
}
IF ELSE STATEMENT
OUTPUT:
Enter an integer: 7
7 is an odd integer.
NESTED IF ELSE STATEMENT
The nested if else statement is that contains an if
else inside the body of the another if else
statements.
If the condition 1 is false the statement three will
be executed ;
Otherwise it contains to perform the second test .
If the condition 2 is true
GENERAL FORM:
if (testExpression1)
{
// statement(s)
}
else if(testExpression2)
{
// statement(s)
}
else if (testExpression 3)
{
// statement(s)
}
.
.
else
{
// statement(s)
}
NESTED IF ELSE STATEMENTS
include <stdio.h>
int main()
{
int number1, number2;
printf("Enter two integers: ");
scanf("%d %d", &number1, &number2);
if (number1 >= number2)
{
if (number1 == number2)
{
printf("Result: %d = %d",number1,number2);
}
NESTED IF ELSE STATEMENT
else
{
printf("Result: %d > %d", number1, number2);
}
}
else
{
printf("Result: %d < %d",number1, number2);
}
return 0;
}
NESTED IF ELSE STATEMENT
OUTPUT:
if (a > b) {
print("Hello");
}
print("Hi");
ELSE IF LADDER
The if...else statement execute two different
codes depending upon whether the test
expression is true or false. Sometimes a choice
has to be made from more than two possibility.
The if else ladder allows you to check for
multiple test expressions and execute various
statement(s).
ELSE IF LADDER
If(marks>79)
grade=“Honours”;
Else if(marks>59)
grade=“First division”;
Else if(marks>49)
grade=“second division”;
Else if(marks>39)
grade=“Third division”;
Else
grade+=“fail”;
Printf(“%s/n”,grade);
ELSE IF LADDER
OUTPUT:
fail.
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.
SWITCH STATEMENT
switch(expression)
{
case value-1:
block-1;
break;
case value-2:
block-2;
break;
case value-3:
block-3;
break;
case value-4:
block-4;
break;
default:
default-block;
break;
}
SWITCH STATEMENT
int i = 1;
switch(i)
{
case 1:
printf("A"); // No break
case 2:
printf("B"); // No break
case 3:
printf("C");
break;
}
SWITCH STATEMENT
OUTPUT:
A B C

More Related Content

What's hot

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
alish sha
 

What's hot (20)

C programming decision making
C programming decision makingC programming decision making
C programming decision making
 
Selection Statements in C Programming
Selection Statements in C ProgrammingSelection Statements in C Programming
Selection Statements in C Programming
 
Control structure of c
Control structure of cControl structure of c
Control structure of c
 
Decision making statements in C
Decision making statements in CDecision making statements in C
Decision making statements in C
 
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
 
Control Flow Statements
Control Flow Statements Control Flow Statements
Control Flow Statements
 
PL SQL Quiz | PL SQL Examples
PL SQL Quiz |  PL SQL ExamplesPL SQL Quiz |  PL SQL Examples
PL SQL Quiz | PL SQL Examples
 
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
 
SQL MCQ
SQL MCQSQL MCQ
SQL MCQ
 
Decision Control Structure If & Else
Decision Control Structure If & ElseDecision Control Structure If & Else
Decision Control Structure If & Else
 
C decision making and looping.
C decision making and looping.C decision making and looping.
C decision making and looping.
 
Decision statements in c language
Decision statements in c languageDecision statements in c language
Decision statements in c language
 
Conditional statement c++
Conditional statement c++Conditional statement c++
Conditional statement c++
 
Control structures in c
Control structures in cControl structures in c
Control structures in c
 
Control structure in c
Control structure in cControl structure in c
Control structure in c
 
5 c control statements looping
5  c control statements looping5  c control statements looping
5 c control statements looping
 
Control Statement programming
Control Statement programmingControl Statement programming
Control Statement programming
 
Branching in C
Branching in CBranching in C
Branching in C
 
Operators and expressions in c language
Operators and expressions in c languageOperators and expressions in c language
Operators and expressions in c language
 
Control statments in c
Control statments in cControl statments in c
Control statments in c
 

Similar to Conditional statements

CONTROLSTRUCTURES.ppt
CONTROLSTRUCTURES.pptCONTROLSTRUCTURES.ppt
CONTROLSTRUCTURES.ppt
Sanjjaayyy
 
exp227-jan-170127160848 (3) (1).pdf
exp227-jan-170127160848 (3) (1).pdfexp227-jan-170127160848 (3) (1).pdf
exp227-jan-170127160848 (3) (1).pdf
mounikanarra3
 
Branching statements
Branching statementsBranching statements
Branching statements
ArunMK17
 

Similar to Conditional statements (20)

Control statement
Control statementControl statement
Control statement
 
C Programming: Control Structure
C Programming: Control StructureC Programming: Control Structure
C Programming: Control Structure
 
CONTROLSTRUCTURES.ppt
CONTROLSTRUCTURES.pptCONTROLSTRUCTURES.ppt
CONTROLSTRUCTURES.ppt
 
Basics of Control Statement in C Languages
Basics of Control Statement in C LanguagesBasics of Control Statement in C Languages
Basics of Control Statement in C Languages
 
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
 
unit 2-Control Structures.pptx
unit 2-Control Structures.pptxunit 2-Control Structures.pptx
unit 2-Control Structures.pptx
 
exp227-jan-170127160848 (3) (1).pdf
exp227-jan-170127160848 (3) (1).pdfexp227-jan-170127160848 (3) (1).pdf
exp227-jan-170127160848 (3) (1).pdf
 
Control statements-Computer programming
Control statements-Computer programmingControl statements-Computer programming
Control statements-Computer programming
 
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
 
C programming Control Structure.pptx
C programming Control Structure.pptxC programming Control Structure.pptx
C programming Control Structure.pptx
 
Programming fundamental 02
Programming fundamental 02Programming fundamental 02
Programming fundamental 02
 
7 functions
7  functions7  functions
7 functions
 
Decision making using if statement
Decision making using if statementDecision making using if statement
Decision making using if statement
 
ICP - Lecture 7 and 8
ICP - Lecture 7 and 8ICP - Lecture 7 and 8
ICP - Lecture 7 and 8
 
Decisions in C or If condition
Decisions in C or If conditionDecisions in C or If condition
Decisions in C or If condition
 
Programming Fundamentals Decisions
Programming Fundamentals  Decisions Programming Fundamentals  Decisions
Programming Fundamentals Decisions
 
Selection & Making Decisions in c
Selection & Making Decisions in cSelection & Making Decisions in c
Selection & Making Decisions in c
 
Branching statements
Branching statementsBranching statements
Branching statements
 
L3 control
L3 controlL3 control
L3 control
 

Recently uploaded

QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lessonQUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
httgc7rh9c
 
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
EADTU
 

Recently uploaded (20)

HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Our Environment Class 10 Science Notes pdf
Our Environment Class 10 Science Notes pdfOur Environment Class 10 Science Notes pdf
Our Environment Class 10 Science Notes pdf
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lessonQUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
Simple, Complex, and Compound Sentences Exercises.pdf
Simple, Complex, and Compound Sentences Exercises.pdfSimple, Complex, and Compound Sentences Exercises.pdf
Simple, Complex, and Compound Sentences Exercises.pdf
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
 
What is 3 Way Matching Process in Odoo 17.pptx
What is 3 Way Matching Process in Odoo 17.pptxWhat is 3 Way Matching Process in Odoo 17.pptx
What is 3 Way Matching Process in Odoo 17.pptx
 

Conditional statements

  • 1. PAPER NAME :CONDITIONAL STATEMENTS. STAFF :D.SARITHA CLASS :I SEMESTER :I UNIT :I TOPIC :PROGRAMMING IN C
  • 3. Forms of if statement Simple if statement. If…else statement. Nested if…else statement. Else .. if ladder.
  • 4. IF STATEMENT If statement is the decision making statement. General form: If (test expression) { statement – block; } statement-x;
  • 5. IF STATEMENTS EXAMPLE PROGRAM : Main() { int a,b,c,d; float ratio; Printf(“Enter four integer valuesn”); Scanf(“%d,%d,%d,%d”,&a,&b,&c,&d); If(c-d !=0) /*execute statement block*/ { ratio = (float)(a+b)/(float)(c-d); printf(“ratio =%fn”,ratio); } }
  • 6. OUTPUT: Enter four integer values 12 23 34 45 ratio=-3.181818.
  • 7. IF… ELSE STATEMENTS If … else statement is the extension of if statement. General form: If (test expression) { //statement (s) } else { //statement(s) }
  • 8. IF ELSE STATEMENTS EXAMPLE PROGRAM: #include <stdio.h> int main() { int number; printf("Enter an integer: "); scanf("%d",&number); // True if remainder is 0 if( number%2 == 0 ) printf("%d is an even integer.",number); else printf("%d is an odd integer.",number); return 0; }
  • 9. IF ELSE STATEMENT OUTPUT: Enter an integer: 7 7 is an odd integer.
  • 10. NESTED IF ELSE STATEMENT The nested if else statement is that contains an if else inside the body of the another if else statements. If the condition 1 is false the statement three will be executed ; Otherwise it contains to perform the second test . If the condition 2 is true
  • 11. GENERAL FORM: if (testExpression1) { // statement(s) } else if(testExpression2) { // statement(s) } else if (testExpression 3) { // statement(s) } . . else { // statement(s) }
  • 12. NESTED IF ELSE STATEMENTS include <stdio.h> int main() { int number1, number2; printf("Enter two integers: "); scanf("%d %d", &number1, &number2); if (number1 >= number2) { if (number1 == number2) { printf("Result: %d = %d",number1,number2); }
  • 13. NESTED IF ELSE STATEMENT else { printf("Result: %d > %d", number1, number2); } } else { printf("Result: %d < %d",number1, number2); } return 0; }
  • 14. NESTED IF ELSE STATEMENT OUTPUT: if (a > b) { print("Hello"); } print("Hi");
  • 15. ELSE IF LADDER The if...else statement execute two different codes depending upon whether the test expression is true or false. Sometimes a choice has to be made from more than two possibility. The if else ladder allows you to check for multiple test expressions and execute various statement(s).
  • 16. ELSE IF LADDER If(marks>79) grade=“Honours”; Else if(marks>59) grade=“First division”; Else if(marks>49) grade=“second division”; Else if(marks>39) grade=“Third division”; Else grade+=“fail”; Printf(“%s/n”,grade);
  • 18. 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.
  • 19. SWITCH STATEMENT switch(expression) { case value-1: block-1; break; case value-2: block-2; break; case value-3: block-3; break; case value-4: block-4; break; default: default-block; break; }
  • 20. SWITCH STATEMENT int i = 1; switch(i) { case 1: printf("A"); // No break case 2: printf("B"); // No break case 3: printf("C"); break; }