SlideShare a Scribd company logo
3
Most read
6
Most read
8
Most read
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

PPTX
C Programming: Control Structure
Sokngim Sa
 
PDF
Control structuresin c
Vikash Dhal
 
PPT
CONTROLSTRUCTURES.ppt
Sanjjaayyy
 
PPT
Decision making using if statement
CHANDAN KUMAR
 
PPTX
chapter 3enejngewngjnjnfjndnennwnnefwf.pptx
TriggeredZulkar
 
PPTX
Basics of Control Statement in C Languages
Dr. Chandrakant Divate
 
PPTX
CONDITIONAL STATEMENT IN C LANGUAGE
Ideal Eyes Business College
 
PDF
Chapter 5 exercises Balagurusamy Programming ANSI in c
BUBT
 
C Programming: Control Structure
Sokngim Sa
 
Control structuresin c
Vikash Dhal
 
CONTROLSTRUCTURES.ppt
Sanjjaayyy
 
Decision making using if statement
CHANDAN KUMAR
 
chapter 3enejngewngjnjnfjndnennwnnefwf.pptx
TriggeredZulkar
 
Basics of Control Statement in C Languages
Dr. Chandrakant Divate
 
CONDITIONAL STATEMENT IN C LANGUAGE
Ideal Eyes Business College
 
Chapter 5 exercises Balagurusamy Programming ANSI in c
BUBT
 

Similar to DECISION MAKING STATEMENTS.pptx (20)

PDF
Chapter 2: Conditional Construct in C++
Amrit Kaur
 
PPT
Cin and cout
Carelon Global Solutions
 
PDF
Loop's definition and practical code in C programming
DharmaKumariBhandari
 
PPTX
control_structures_c_language_regarding how to represent the loop in language...
ShirishaBuduputi
 
PDF
ICP - Lecture 7 and 8
Hassaan Rahman
 
PPTX
Branching statements
ArunMK17
 
PPTX
Control and conditional statements
rajshreemuthiah
 
DOCX
C Control Statements.docx
JavvajiVenkat
 
PDF
Control statements-Computer programming
nmahi96
 
PDF
Fundamental of Information Technology - UNIT 8
Shipra Swati
 
PPTX
M2 (1).pptxisedepofengiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii
rakshithatan
 
PDF
C Programming Unit II Sharad Institute college
SatishPise4
 
DOCX
Statement
Ahmad Kamal
 
PDF
Control structure and Looping statements
BalaKrishnan466
 
PPTX
COM1407: Program Control Structures – Decision Making & Branching
Hemantha Kulathilake
 
PDF
CP Handout#4
trupti1976
 
PDF
control statement
Kathmandu University
 
PDF
answer-model-qp-15-pcd13pcd
Syed Mustafa
 
PDF
VTU PCD Model Question Paper - Programming in C
Syed Mustafa
 
PPTX
C programming Control Structure.pptx
DEEPAK948083
 
Chapter 2: Conditional Construct in C++
Amrit Kaur
 
Loop's definition and practical code in C programming
DharmaKumariBhandari
 
control_structures_c_language_regarding how to represent the loop in language...
ShirishaBuduputi
 
ICP - Lecture 7 and 8
Hassaan Rahman
 
Branching statements
ArunMK17
 
Control and conditional statements
rajshreemuthiah
 
C Control Statements.docx
JavvajiVenkat
 
Control statements-Computer programming
nmahi96
 
Fundamental of Information Technology - UNIT 8
Shipra Swati
 
M2 (1).pptxisedepofengiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii
rakshithatan
 
C Programming Unit II Sharad Institute college
SatishPise4
 
Statement
Ahmad Kamal
 
Control structure and Looping statements
BalaKrishnan466
 
COM1407: Program Control Structures – Decision Making & Branching
Hemantha Kulathilake
 
CP Handout#4
trupti1976
 
control statement
Kathmandu University
 
answer-model-qp-15-pcd13pcd
Syed Mustafa
 
VTU PCD Model Question Paper - Programming in C
Syed Mustafa
 
C programming Control Structure.pptx
DEEPAK948083
 
Ad

More from yashodamb (10)

PPTX
conversion of Infix to Postfix conversion using stack
yashodamb
 
PPTX
Introduction to Cloud computing concept.pptx
yashodamb
 
PPTX
Introduction to Database Management System.pptx
yashodamb
 
PDF
Unit-3 greedy method, Prim's algorithm, Kruskal's algorithm.pdf
yashodamb
 
PDF
Cascading style sheet: complete explanation with some examples
yashodamb
 
PPTX
applets.pptx
yashodamb
 
PPTX
Navigation between the worksheets.pptx
yashodamb
 
PPTX
Implementing a Java Program.pptx
yashodamb
 
PPTX
Thread life cycle.pptx
yashodamb
 
PPTX
History of C programming.pptx
yashodamb
 
conversion of Infix to Postfix conversion using stack
yashodamb
 
Introduction to Cloud computing concept.pptx
yashodamb
 
Introduction to Database Management System.pptx
yashodamb
 
Unit-3 greedy method, Prim's algorithm, Kruskal's algorithm.pdf
yashodamb
 
Cascading style sheet: complete explanation with some examples
yashodamb
 
applets.pptx
yashodamb
 
Navigation between the worksheets.pptx
yashodamb
 
Implementing a Java Program.pptx
yashodamb
 
Thread life cycle.pptx
yashodamb
 
History of C programming.pptx
yashodamb
 
Ad

Recently uploaded (20)

PPTX
How to Track Skills & Contracts Using Odoo 18 Employee
Celine George
 
PPTX
CDH. pptx
AneetaSharma15
 
PPTX
family health care settings home visit - unit 6 - chn 1 - gnm 1st year.pptx
Priyanshu Anand
 
PPTX
Artificial-Intelligence-in-Drug-Discovery by R D Jawarkar.pptx
Rahul Jawarkar
 
PPTX
Kanban Cards _ Mass Action in Odoo 18.2 - Odoo Slides
Celine George
 
DOCX
Unit 5: Speech-language and swallowing disorders
JELLA VISHNU DURGA PRASAD
 
DOCX
SAROCES Action-Plan FOR ARAL PROGRAM IN DEPED
Levenmartlacuna1
 
PDF
Review of Related Literature & Studies.pdf
Thelma Villaflores
 
PDF
The Minister of Tourism, Culture and Creative Arts, Abla Dzifa Gomashie has e...
nservice241
 
PPTX
An introduction to Prepositions for beginners.pptx
drsiddhantnagine
 
PPTX
Python-Application-in-Drug-Design by R D Jawarkar.pptx
Rahul Jawarkar
 
PDF
Antianginal agents, Definition, Classification, MOA.pdf
Prerana Jadhav
 
PPTX
Basics and rules of probability with real-life uses
ravatkaran694
 
PPTX
Five Point Someone – Chetan Bhagat | Book Summary & Analysis by Bhupesh Kushwaha
Bhupesh Kushwaha
 
PDF
Biological Classification Class 11th NCERT CBSE NEET.pdf
NehaRohtagi1
 
PPTX
An introduction to Dialogue writing.pptx
drsiddhantnagine
 
DOCX
Action Plan_ARAL PROGRAM_ STAND ALONE SHS.docx
Levenmartlacuna1
 
PDF
Health-The-Ultimate-Treasure (1).pdf/8th class science curiosity /samyans edu...
Sandeep Swamy
 
PPTX
HISTORY COLLECTION FOR PSYCHIATRIC PATIENTS.pptx
PoojaSen20
 
PPTX
BASICS IN COMPUTER APPLICATIONS - UNIT I
suganthim28
 
How to Track Skills & Contracts Using Odoo 18 Employee
Celine George
 
CDH. pptx
AneetaSharma15
 
family health care settings home visit - unit 6 - chn 1 - gnm 1st year.pptx
Priyanshu Anand
 
Artificial-Intelligence-in-Drug-Discovery by R D Jawarkar.pptx
Rahul Jawarkar
 
Kanban Cards _ Mass Action in Odoo 18.2 - Odoo Slides
Celine George
 
Unit 5: Speech-language and swallowing disorders
JELLA VISHNU DURGA PRASAD
 
SAROCES Action-Plan FOR ARAL PROGRAM IN DEPED
Levenmartlacuna1
 
Review of Related Literature & Studies.pdf
Thelma Villaflores
 
The Minister of Tourism, Culture and Creative Arts, Abla Dzifa Gomashie has e...
nservice241
 
An introduction to Prepositions for beginners.pptx
drsiddhantnagine
 
Python-Application-in-Drug-Design by R D Jawarkar.pptx
Rahul Jawarkar
 
Antianginal agents, Definition, Classification, MOA.pdf
Prerana Jadhav
 
Basics and rules of probability with real-life uses
ravatkaran694
 
Five Point Someone – Chetan Bhagat | Book Summary & Analysis by Bhupesh Kushwaha
Bhupesh Kushwaha
 
Biological Classification Class 11th NCERT CBSE NEET.pdf
NehaRohtagi1
 
An introduction to Dialogue writing.pptx
drsiddhantnagine
 
Action Plan_ARAL PROGRAM_ STAND ALONE SHS.docx
Levenmartlacuna1
 
Health-The-Ultimate-Treasure (1).pdf/8th class science curiosity /samyans edu...
Sandeep Swamy
 
HISTORY COLLECTION FOR PSYCHIATRIC PATIENTS.pptx
PoojaSen20
 
BASICS IN COMPUTER APPLICATIONS - UNIT I
suganthim28
 

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