SlideShare a Scribd company logo
1 of 20
DECISION MAKING
STATEMENTS
Prof. Yashoda M B
Assistant Professor
Computer Science (UG)
Kristu Jayanti college
Bengaluru
if Statement
if- else Statement
if-else ladder
Nested if statement
switch statement
17/11/2023
2
Kristu Jayanti College
if statement: Syntax
17/11/2023
3
Kristu Jayanti College
Flowchart
17/11/2023
4
Kristu Jayanti College
Algorithm: To check the number is positive.
Step 1: Start
Step 2: Read a number and store in the variable Num.
Step 3: If the number stored in the variable Num is grater
than 0, print “ The number is Positive”.
Step 4: Stop
17/11/2023
5
Kristu Jayanti College
Example: C program to check the given number is positive.
#include<stdio.h>
#include<conio.h>
void main()
{
int Num;
clrscr();
printf(“enter a numbern”);
scanf(“%d”,&Num);
// if statement
if(Num>0)
printf(“The number is positive”);
getch();
}
17/11/2023
6
Kristu Jayanti College
if-else statement: Syntax
17/11/2023
7
Kristu Jayanti College
Flowchart
17/11/2023
8
Kristu Jayanti College
Algorithm: To check the number is positive
or negative.
Step 1: Start
Step 2: Read a number and store in the variable Num.
Step 3: If the number stored in the variable Num is grater
than 0 go to Step 4, otherwise, go to step 5.
Step 4: print “ The number is Positive”. Goto Step 6.
Step 5: Print “The number is Negative”.
Step 6: Stop
17/11/2023
9
Kristu Jayanti College
Example: C program to check the given number is positive or negative.
#include<stdio.h>
#include<conio.h>
void main()
{
int Num;
clrscr();
printf(“enter a numbern”);
scanf(“%d”,&Num);
// if else ladder
if(Num>0)
printf(“The number is positive”);
else
printf(“The number is negative”);
getch();
} 17/11/2023
10
Kristu Jayanti College
if-else ladder statement: Syntax
// any if-else ladder starts with an if statement only
if(condition1)
{
// statements
}
else if(condition2)
{
// this else if will be executed when condition in if is false and
// the condition of this else if is true
}
.... // once if-else ladder can have multiple else if
else
{
// at the end we put else
} 17/11/2023
11
Kristu Jayanti College
Flowchart
17/11/2023
12
Kristu Jayanti College
Example: C program to check the given number is positive or negative.
#include<stdio.h>
#include<conio.h>
void main()
{
int Num;
clrscr();
printf(“enter a numbern”);
scanf(“%d”,&Num);
// if else ladder
if(Num>0)
printf(“The number is positive”);
else if(Num<0)
printf(“The number is negative”);
else
printf(“The number is zero”);
getch();
17/11/2023
13
Kristu Jayanti College
nested if statement: Syntax
17/11/2023
14
Kristu Jayanti College
Flowchart
17/11/2023
15
Kristu Jayanti College
Example: C program to check the given number is positive or negative.
i) If positive, check whether if is odd or even
ii) if negative, display its square.
#include<stdio.h>
#include<conio.h>
void main() {
int Num;
clrscr();
printf(“enter a numbern”);
scanf(“%d”,&Num); // reading a number
if(Num>0)
{
printf(“The number is positive”);
if(Num%2==0) //nested if
printf(“The number is even”);
else
printf(“The number is odd”);
}
else {
printf(“The number is positive”);
printf(“The square of the number is %d”, Num*Num);
}
getch();
}
17/11/2023
16
Kristu Jayanti College
switch statement: Syntax
switch(expression)
{
case value1: statement_1;
break;
case value2: statement_2;
break;
. . .
case value_n: statement_n;
break;
default: default_statement;
} 17/11/2023
17
Kristu Jayanti College
Flowchart
17/11/2023
18
Kristu Jayanti College
Example: C program to display the day on user’s choice using switch statement.
#include<stdio.h>
#include<conio.h>
void main() {
int choice;
clrscr();
printf(“enter a choicen”);
scanf(“%d”,&choice); // reading a number
switch(choice) {
case 1: printf(“It is Monday”); break;
case 2: printf(“It is Tuesday”); break;
case 3: printf(“It is Wednesday”); break;
case 4: printf(“It is Thursday”); break;
case 5: printf(“It is Friday”); break;
case 6: printf(“It is Saturday”); break;
case 7: printf(“It is Sunday”); break;
default: printf(“Invalid choice”);
}
getch();
} 17/11/2023
19
Kristu Jayanti College
17/11/2023
20
Kristu Jayanti College

More Related Content

Similar to DECISION MAKING STATEMENTS.pptx

Branching statements
Branching statementsBranching statements
Branching statements
ArunMK17
 
M2 (1).pptxisedepofengiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii
M2 (1).pptxisedepofengiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiM2 (1).pptxisedepofengiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii
M2 (1).pptxisedepofengiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii
rakshithatan
 

Similar to DECISION MAKING STATEMENTS.pptx (16)

Cin and cout
Cin and coutCin and cout
Cin and cout
 
Loop's definition and practical code in C programming
Loop's definition and  practical code in C programming Loop's definition and  practical code in C programming
Loop's definition and practical code in C programming
 
ICP - Lecture 7 and 8
ICP - Lecture 7 and 8ICP - Lecture 7 and 8
ICP - Lecture 7 and 8
 
Branching statements
Branching statementsBranching statements
Branching statements
 
Control and conditional statements
Control and conditional statementsControl and conditional statements
Control and conditional statements
 
C Control Statements.docx
C Control Statements.docxC Control Statements.docx
C Control Statements.docx
 
Control statements-Computer programming
Control statements-Computer programmingControl statements-Computer programming
Control statements-Computer programming
 
Fundamental of Information Technology - UNIT 8
Fundamental of Information Technology - UNIT 8Fundamental of Information Technology - UNIT 8
Fundamental of Information Technology - UNIT 8
 
M2 (1).pptxisedepofengiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii
M2 (1).pptxisedepofengiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiM2 (1).pptxisedepofengiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii
M2 (1).pptxisedepofengiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii
 
Statement
StatementStatement
Statement
 
COM1407: Program Control Structures – Decision Making & Branching
COM1407: Program Control Structures – Decision Making & BranchingCOM1407: Program Control Structures – Decision Making & Branching
COM1407: Program Control Structures – Decision Making & Branching
 
CP Handout#4
CP Handout#4CP Handout#4
CP Handout#4
 
control statement
control statement control statement
control statement
 
VTU PCD Model Question Paper - Programming in C
VTU PCD Model Question Paper - Programming in CVTU PCD Model Question Paper - Programming in C
VTU PCD Model Question Paper - Programming in C
 
answer-model-qp-15-pcd13pcd
answer-model-qp-15-pcd13pcdanswer-model-qp-15-pcd13pcd
answer-model-qp-15-pcd13pcd
 
C programming Control Structure.pptx
C programming Control Structure.pptxC programming Control Structure.pptx
C programming Control Structure.pptx
 

More from yashodamb (7)

Unit-3 greedy method, Prim's algorithm, Kruskal's algorithm.pdf
Unit-3 greedy method, Prim's algorithm, Kruskal's algorithm.pdfUnit-3 greedy method, Prim's algorithm, Kruskal's algorithm.pdf
Unit-3 greedy method, Prim's algorithm, Kruskal's algorithm.pdf
 
Cascading style sheet: complete explanation with some examples
Cascading style sheet: complete explanation with some examplesCascading style sheet: complete explanation with some examples
Cascading style sheet: complete explanation with some examples
 
applets.pptx
applets.pptxapplets.pptx
applets.pptx
 
Navigation between the worksheets.pptx
Navigation between the worksheets.pptxNavigation between the worksheets.pptx
Navigation between the worksheets.pptx
 
Implementing a Java Program.pptx
Implementing a Java Program.pptxImplementing a Java Program.pptx
Implementing a Java Program.pptx
 
Thread life cycle.pptx
Thread life cycle.pptxThread life cycle.pptx
Thread life cycle.pptx
 
History of C programming.pptx
History of C programming.pptxHistory of C programming.pptx
History of C programming.pptx
 

Recently uploaded

會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
中 央社
 
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
中 央社
 

Recently uploaded (20)

AIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptAIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.ppt
 
male presentation...pdf.................
male presentation...pdf.................male presentation...pdf.................
male presentation...pdf.................
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
 
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
 
The Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDFThe Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDF
 
PSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxPSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptx
 
8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital Management8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital Management
 
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfFICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
 
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptxAnalyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
 
Đề tieng anh thpt 2024 danh cho cac ban hoc sinh
Đề tieng anh thpt 2024 danh cho cac ban hoc sinhĐề tieng anh thpt 2024 danh cho cac ban hoc sinh
Đề tieng anh thpt 2024 danh cho cac ban hoc sinh
 
MOOD STABLIZERS DRUGS.pptx
MOOD     STABLIZERS           DRUGS.pptxMOOD     STABLIZERS           DRUGS.pptx
MOOD STABLIZERS DRUGS.pptx
 
OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...
 
Mattingly "AI and Prompt Design: LLMs with NER"
Mattingly "AI and Prompt Design: LLMs with NER"Mattingly "AI and Prompt Design: LLMs with NER"
Mattingly "AI and Prompt Design: LLMs with NER"
 
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading RoomSternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
 
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjStl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
 
Including Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdfIncluding Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdf
 
e-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopale-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopal
 
Supporting Newcomer Multilingual Learners
Supporting Newcomer  Multilingual LearnersSupporting Newcomer  Multilingual Learners
Supporting Newcomer Multilingual Learners
 
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
 

DECISION MAKING STATEMENTS.pptx

  • 1. DECISION MAKING STATEMENTS Prof. Yashoda M B Assistant Professor Computer Science (UG) Kristu Jayanti college Bengaluru
  • 2. if Statement if- else Statement if-else ladder Nested if statement switch statement 17/11/2023 2 Kristu Jayanti College
  • 5. Algorithm: To check the number is positive. Step 1: Start Step 2: Read a number and store in the variable Num. Step 3: If the number stored in the variable Num is grater than 0, print “ The number is Positive”. Step 4: Stop 17/11/2023 5 Kristu Jayanti College
  • 6. Example: C program to check the given number is positive. #include<stdio.h> #include<conio.h> void main() { int Num; clrscr(); printf(“enter a numbern”); scanf(“%d”,&Num); // if statement if(Num>0) printf(“The number is positive”); getch(); } 17/11/2023 6 Kristu Jayanti College
  • 9. Algorithm: To check the number is positive or negative. Step 1: Start Step 2: Read a number and store in the variable Num. Step 3: If the number stored in the variable Num is grater than 0 go to Step 4, otherwise, go to step 5. Step 4: print “ The number is Positive”. Goto Step 6. Step 5: Print “The number is Negative”. Step 6: Stop 17/11/2023 9 Kristu Jayanti College
  • 10. Example: C program to check the given number is positive or negative. #include<stdio.h> #include<conio.h> void main() { int Num; clrscr(); printf(“enter a numbern”); scanf(“%d”,&Num); // if else ladder if(Num>0) printf(“The number is positive”); else printf(“The number is negative”); getch(); } 17/11/2023 10 Kristu Jayanti College
  • 11. if-else ladder statement: Syntax // any if-else ladder starts with an if statement only if(condition1) { // statements } else if(condition2) { // this else if will be executed when condition in if is false and // the condition of this else if is true } .... // once if-else ladder can have multiple else if else { // at the end we put else } 17/11/2023 11 Kristu Jayanti College
  • 13. Example: C program to check the given number is positive or negative. #include<stdio.h> #include<conio.h> void main() { int Num; clrscr(); printf(“enter a numbern”); scanf(“%d”,&Num); // if else ladder if(Num>0) printf(“The number is positive”); else if(Num<0) printf(“The number is negative”); else printf(“The number is zero”); getch(); 17/11/2023 13 Kristu Jayanti College
  • 14. nested if statement: Syntax 17/11/2023 14 Kristu Jayanti College
  • 16. Example: C program to check the given number is positive or negative. i) If positive, check whether if is odd or even ii) if negative, display its square. #include<stdio.h> #include<conio.h> void main() { int Num; clrscr(); printf(“enter a numbern”); scanf(“%d”,&Num); // reading a number if(Num>0) { printf(“The number is positive”); if(Num%2==0) //nested if printf(“The number is even”); else printf(“The number is odd”); } else { printf(“The number is positive”); printf(“The square of the number is %d”, Num*Num); } getch(); } 17/11/2023 16 Kristu Jayanti College
  • 17. switch statement: Syntax switch(expression) { case value1: statement_1; break; case value2: statement_2; break; . . . case value_n: statement_n; break; default: default_statement; } 17/11/2023 17 Kristu Jayanti College
  • 19. Example: C program to display the day on user’s choice using switch statement. #include<stdio.h> #include<conio.h> void main() { int choice; clrscr(); printf(“enter a choicen”); scanf(“%d”,&choice); // reading a number switch(choice) { case 1: printf(“It is Monday”); break; case 2: printf(“It is Tuesday”); break; case 3: printf(“It is Wednesday”); break; case 4: printf(“It is Thursday”); break; case 5: printf(“It is Friday”); break; case 6: printf(“It is Saturday”); break; case 7: printf(“It is Sunday”); break; default: printf(“Invalid choice”); } getch(); } 17/11/2023 19 Kristu Jayanti College