SlideShare a Scribd company logo
Computer Programming:
C language
Subject Teacher:
Abdul Rehman
Lecture – 17 & 18
The Decision Control Structure
• Decision making statements are used to skip or to execute a group of
statements based on the result of some condition.
• The decision making statements are,
− simple if statement
− if…else statement
− nested if
− else … if ladder
− switch statement
− goto
• These statements are also called branching statements
IF Statement
• if statement executes a single statement or a block of statements if a
boolean expression evaluates to true.
Syntax:
If(condition)
{
Statements;
}
Here condition is a boolean expression
If condition is true, then the statement is executed
If condition is false, than the statement is bypassed
Simple if statement
Syntax:
if(condition)
{
Statements;
}
if(condition)
Statements;
False
True (Bypass)
Simple if - Example
#include<stdio.h>
#include<conio.h>
int main()
{
int num1,num2;
printf("Enter any two numbers ");
scanf("%d %d",&num1,&num2);
if(num1>num2)
printf("nNum1 is greater than Num2");
printf("nEnd of program");
getch();
}
Output1
Enter any two numbers 10 5
Num1 is greater than Num2
End of program
Output1
Enter any two numbers 10 50
End of program
IF Else Statement
• An if statement can include an else clause that executes a statement or block
if the boolean expression is not true.
Syntax:
If (condition)
Statement1;
Else
Statement2;
• If condition is true, then statement1 is executed.
• Otherwise, statement2 is executed.
if - else statement
Syntax:
if(condition)
{
True block statements;
}
else
{
False block statements;
}
if(condi
tion)
True Block
Statement
False
True
False Block
Statements
if – else Example
# include <stdio.h>
void main ()
{
int num;
printf ("Type a number:");
scanf ("%d", &num);
if (number < 0)
printf(“The number is negative”);
else
printf(“The number is positive”);
}
Output
Type a number 50
The number is positive
if – else Example
#include<stdio.h>
void main()
{
Int num;
printf ("Enter a number:");
scanf ("%d",&num);
if (num%2==0)
printf ("The number is
EVEN.n");
else
printf ("The number is
ODD.n");
}
Output
Enter a number 125
The number is ODD
if – else Example
#include<stdio.h>
#include<conio.h>
void main (void)
{
int percentage;
printf(“Enter your percentage: “);
scanf(“%d”, &percentage);
if(percentage>=60)
printf(“You are Passed”);
else
printf(“You are failed”);
getch();
}
Else - if Ladder Statement
• An if statement can be followed by an optional else
if...else statement, which is very useful to test various
conditions using single if...else if statement.
When using if , else if , else statements there are few points to
keep in mind:
• An if can have zero or one else's and it must come after any
else if's.
• An if can have zero to many else if's and they must come
before the else.
• Once an else if succeeds, none of the remaining else if's or
else's will be tested.
Else - if Ladder Statement
Syntax
if (condition1)
statement block 1;
else if (condition2)
statement block 2;
else if (condition3)
statement block 3;
:
:
else if (condition)
statement block n;
else
default statement;
Else - if Ladder Statement
If(condition1)
Default Statements;
True
False
Statements1;
Else if(condition2)
True
Statements2;
False
Else if(condition3)
Statements3;
False
True
Else - if Ladder Example
#include<stdio.h>
#include<conio.h>
void main(void)
{
int num1,num2;
clrscr();
printf(“Enter integer numbers to check: ”);
scanf(“%d %d”,&num1,&num2);
if(num1>num2)
printf(“num1 is greater than num2”);
else if(num1<num2)
printf(“num1 is less than num2”);
else
printf(“both numbers are equal”);
getch();
}
Else - if Ladder Example
#include <stdio.h>
void main ()
{
float perc;
printf ("Enter Percentage:");
scanf ("%f", &perc);
if (perc <= 100 && perc >= 80)
printf ("n A-1 Grade");
else if (perc >= 70)
printf("n A Grade");
else if (perc >= 60)
printf ("n B Grade");
else
printf ("Fail");
}
Output
Enter Percentage: 75
A Grade
Else - if Ladder Example
#include<stdio.h>
#include<conio.h>
int main()
{
float num1, num2; char op;
printf("Enter two numbers");
scanf("%f %f",&num1,&num2);
printf("nEnter operator (+,-,*,/)");
op=getche();
if(op =='+')
printf("nResult=%f",num1+num2);
else if(op == '-')
printf("nResult=%f",num1-num2);
else if(op == '*')
printf("nResult=%f",num1*num2);
else if(op == '/')
printf("nResult=%f",num1/num2);
else
printf("Invalid Operator");
getch(); }

More Related Content

What's hot (20)

PPTX
C statements
Ahsann111
 
PPT
M C6java5
mbruggen
 
PPTX
Decision control structures
Rahul Bathri
 
PPTX
Selection statements
Harsh Dabas
 
PPT
M C6java6
mbruggen
 
PPT
The Three Basic Selection Structures in C++ Programming Concepts
Tech
 
PPTX
Switch statement, break statement, go to statement
Raj Parekh
 
PPTX
C# conditional branching statement
baabtra.com - No. 1 supplier of quality freshers
 
PPTX
Java if else condition - powerpoint persentation
Maneesha Caldera
 
PPSX
Bsit1
jigeno
 
PPTX
Cse lecture-6-c control statement
FarshidKhan
 
PPTX
java programming- control statements
jyoti_lakhani
 
PPTX
Java Decision Control
Jayfee Ramos
 
PPTX
If statements in c programming
Archana Gopinath
 
PPT
Cprogrammingprogramcontrols
teach4uin
 
PPTX
Constructs (Programming Methodology)
Jyoti Bhardwaj
 
PPTX
Dti2143 chap 4 control structures aka_selection
alish sha
 
C statements
Ahsann111
 
M C6java5
mbruggen
 
Decision control structures
Rahul Bathri
 
Selection statements
Harsh Dabas
 
M C6java6
mbruggen
 
The Three Basic Selection Structures in C++ Programming Concepts
Tech
 
Switch statement, break statement, go to statement
Raj Parekh
 
C# conditional branching statement
baabtra.com - No. 1 supplier of quality freshers
 
Java if else condition - powerpoint persentation
Maneesha Caldera
 
Bsit1
jigeno
 
Cse lecture-6-c control statement
FarshidKhan
 
java programming- control statements
jyoti_lakhani
 
Java Decision Control
Jayfee Ramos
 
If statements in c programming
Archana Gopinath
 
Cprogrammingprogramcontrols
teach4uin
 
Constructs (Programming Methodology)
Jyoti Bhardwaj
 
Dti2143 chap 4 control structures aka_selection
alish sha
 

Viewers also liked (17)

PDF
Introduction of c_language
SINGH PROJECTS
 
PPTX
fundamentals of c
Vijayalaxmi Wakode
 
PPT
Oops And C++ Fundamentals
Subhasis Nayak
 
PPTX
Uses of computers
Nazmul Hetfield Batchu
 
PDF
Data Structure in C Programming Language
Arkadeep Dey
 
PDF
Lecture 2 history_of_c
eShikshak
 
PPTX
C++ history session 00 history
Arun Prakash
 
PPTX
Victorian Crisis in Tennyson’s "Lotos Eaters"
Nazmul Hetfield Batchu
 
PPT
Computer History
Crystal Cunningham
 
PPTX
Array in c language
home
 
PPTX
C Programming Language Tutorial for beginners - JavaTpoint
JavaTpoint.Com
 
PPSX
INTRODUCTION TO C PROGRAMMING
Abhishek Dwivedi
 
PPT
History Of Computer
guest420b9d
 
PPTX
Generations of computer
Jatin Jindal
 
PPT
Basics of C programming
avikdhupar
 
PDF
Learning c - An extensive guide to learn the C Language
Abhishek Dwivedi
 
PPTX
GENERATION OF COMPUTERS.
Sowjanya Sampathkumar
 
Introduction of c_language
SINGH PROJECTS
 
fundamentals of c
Vijayalaxmi Wakode
 
Oops And C++ Fundamentals
Subhasis Nayak
 
Uses of computers
Nazmul Hetfield Batchu
 
Data Structure in C Programming Language
Arkadeep Dey
 
Lecture 2 history_of_c
eShikshak
 
C++ history session 00 history
Arun Prakash
 
Victorian Crisis in Tennyson’s "Lotos Eaters"
Nazmul Hetfield Batchu
 
Computer History
Crystal Cunningham
 
Array in c language
home
 
C Programming Language Tutorial for beginners - JavaTpoint
JavaTpoint.Com
 
INTRODUCTION TO C PROGRAMMING
Abhishek Dwivedi
 
History Of Computer
guest420b9d
 
Generations of computer
Jatin Jindal
 
Basics of C programming
avikdhupar
 
Learning c - An extensive guide to learn the C Language
Abhishek Dwivedi
 
GENERATION OF COMPUTERS.
Sowjanya Sampathkumar
 
Ad

Similar to programming c language. (20)

PPTX
Basics of Control Statement in C Languages
Dr. Chandrakant Divate
 
PDF
if else.pdf
Avijeetyadav
 
PDF
Unit ii chapter 2 Decision making and Branching in C
Sowmya Jyothi
 
PPTX
CH-4 (1).pptx
Mehul Desai
 
PPTX
6 Control Structures-1.pptxAAAAAAAAAAAAAAAAAAAAA
EG20910848921ISAACDU
 
PPTX
control_structures_c_language_regarding how to represent the loop in language...
ShirishaBuduputi
 
PDF
C programming decision making
SENA
 
PDF
C Programming Unit II Sharad Institute college
SatishPise4
 
PPTX
Control Statements -if else in C programming.pptx
ganeshmahato20
 
PPT
Lecture 6Decision_Control_OR_Conditional_Control_Structures.ppt
LaxmiVaraprasad1
 
PPT
Fcp chapter 2 upto_if_else (2)
Jagdish Kamble
 
PPTX
Conditional statements
NabishaAK
 
PDF
Decision Making Statements, Arrays, Strings
Prabu U
 
PPTX
Decision Control Structure If & Else
Abdullah Bhojani
 
PDF
control statement
Kathmandu University
 
PPTX
Selection structure
Jyoti Pokharna
 
DOCX
C Control Statements.docx
JavvajiVenkat
 
PPTX
Control structures(class 02)
Vinoth Chandrasekaran
 
PDF
175035 cse lab-03
Mahbubay Rabbani Mim
 
PDF
Programming Fundamentals Decisions
imtiazalijoono
 
Basics of Control Statement in C Languages
Dr. Chandrakant Divate
 
if else.pdf
Avijeetyadav
 
Unit ii chapter 2 Decision making and Branching in C
Sowmya Jyothi
 
CH-4 (1).pptx
Mehul Desai
 
6 Control Structures-1.pptxAAAAAAAAAAAAAAAAAAAAA
EG20910848921ISAACDU
 
control_structures_c_language_regarding how to represent the loop in language...
ShirishaBuduputi
 
C programming decision making
SENA
 
C Programming Unit II Sharad Institute college
SatishPise4
 
Control Statements -if else in C programming.pptx
ganeshmahato20
 
Lecture 6Decision_Control_OR_Conditional_Control_Structures.ppt
LaxmiVaraprasad1
 
Fcp chapter 2 upto_if_else (2)
Jagdish Kamble
 
Conditional statements
NabishaAK
 
Decision Making Statements, Arrays, Strings
Prabu U
 
Decision Control Structure If & Else
Abdullah Bhojani
 
control statement
Kathmandu University
 
Selection structure
Jyoti Pokharna
 
C Control Statements.docx
JavvajiVenkat
 
Control structures(class 02)
Vinoth Chandrasekaran
 
175035 cse lab-03
Mahbubay Rabbani Mim
 
Programming Fundamentals Decisions
imtiazalijoono
 
Ad

More from Abdul Rehman (8)

PDF
Introduction Relational Marketing
Abdul Rehman
 
PPT
Software Engineering
Abdul Rehman
 
PDF
Introduction To Autumata Theory
Abdul Rehman
 
PDF
Query optimization in SQL
Abdul Rehman
 
DOC
computer System UNit Every thing
Abdul Rehman
 
PPTX
Education system in Pakistan
Abdul Rehman
 
PPTX
How to write a letter
Abdul Rehman
 
PPTX
Writing good paragraphs ppt
Abdul Rehman
 
Introduction Relational Marketing
Abdul Rehman
 
Software Engineering
Abdul Rehman
 
Introduction To Autumata Theory
Abdul Rehman
 
Query optimization in SQL
Abdul Rehman
 
computer System UNit Every thing
Abdul Rehman
 
Education system in Pakistan
Abdul Rehman
 
How to write a letter
Abdul Rehman
 
Writing good paragraphs ppt
Abdul Rehman
 

Recently uploaded (20)

PDF
MiniTool Partition Wizard Free Crack + Full Free Download 2025
bashirkhan333g
 
PDF
vMix Pro 28.0.0.42 Download vMix Registration key Bundle
kulindacore
 
PPTX
Homogeneity of Variance Test Options IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PPTX
OpenChain @ OSS NA - In From the Cold: Open Source as Part of Mainstream Soft...
Shane Coughlan
 
PPTX
Finding Your License Details in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PPTX
Agentic Automation: Build & Deploy Your First UiPath Agent
klpathrudu
 
PDF
Generic or Specific? Making sensible software design decisions
Bert Jan Schrijver
 
PDF
4K Video Downloader Plus Pro Crack for MacOS New Download 2025
bashirkhan333g
 
PDF
Alexander Marshalov - How to use AI Assistants with your Monitoring system Q2...
VictoriaMetrics
 
PDF
Wondershare PDFelement Pro Crack for MacOS New Version Latest 2025
bashirkhan333g
 
PDF
Empower Your Tech Vision- Why Businesses Prefer to Hire Remote Developers fro...
logixshapers59
 
PDF
Odoo CRM vs Zoho CRM: Honest Comparison 2025
Odiware Technologies Private Limited
 
PPTX
Help for Correlations in IBM SPSS Statistics.pptx
Version 1 Analytics
 
PDF
Download Canva Pro 2025 PC Crack Full Latest Version
bashirkhan333g
 
PDF
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pdf
Varsha Nayak
 
PDF
Build It, Buy It, or Already Got It? Make Smarter Martech Decisions
bbedford2
 
PDF
How to Hire AI Developers_ Step-by-Step Guide in 2025.pdf
DianApps Technologies
 
PDF
Open Chain Q2 Steering Committee Meeting - 2025-06-25
Shane Coughlan
 
PPTX
Tally software_Introduction_Presentation
AditiBansal54083
 
PDF
Driver Easy Pro 6.1.1 Crack Licensce key 2025 FREE
utfefguu
 
MiniTool Partition Wizard Free Crack + Full Free Download 2025
bashirkhan333g
 
vMix Pro 28.0.0.42 Download vMix Registration key Bundle
kulindacore
 
Homogeneity of Variance Test Options IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
OpenChain @ OSS NA - In From the Cold: Open Source as Part of Mainstream Soft...
Shane Coughlan
 
Finding Your License Details in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
Agentic Automation: Build & Deploy Your First UiPath Agent
klpathrudu
 
Generic or Specific? Making sensible software design decisions
Bert Jan Schrijver
 
4K Video Downloader Plus Pro Crack for MacOS New Download 2025
bashirkhan333g
 
Alexander Marshalov - How to use AI Assistants with your Monitoring system Q2...
VictoriaMetrics
 
Wondershare PDFelement Pro Crack for MacOS New Version Latest 2025
bashirkhan333g
 
Empower Your Tech Vision- Why Businesses Prefer to Hire Remote Developers fro...
logixshapers59
 
Odoo CRM vs Zoho CRM: Honest Comparison 2025
Odiware Technologies Private Limited
 
Help for Correlations in IBM SPSS Statistics.pptx
Version 1 Analytics
 
Download Canva Pro 2025 PC Crack Full Latest Version
bashirkhan333g
 
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pdf
Varsha Nayak
 
Build It, Buy It, or Already Got It? Make Smarter Martech Decisions
bbedford2
 
How to Hire AI Developers_ Step-by-Step Guide in 2025.pdf
DianApps Technologies
 
Open Chain Q2 Steering Committee Meeting - 2025-06-25
Shane Coughlan
 
Tally software_Introduction_Presentation
AditiBansal54083
 
Driver Easy Pro 6.1.1 Crack Licensce key 2025 FREE
utfefguu
 

programming c language.

  • 1. Computer Programming: C language Subject Teacher: Abdul Rehman Lecture – 17 & 18
  • 2. The Decision Control Structure • Decision making statements are used to skip or to execute a group of statements based on the result of some condition. • The decision making statements are, − simple if statement − if…else statement − nested if − else … if ladder − switch statement − goto • These statements are also called branching statements
  • 3. IF Statement • if statement executes a single statement or a block of statements if a boolean expression evaluates to true. Syntax: If(condition) { Statements; } Here condition is a boolean expression If condition is true, then the statement is executed If condition is false, than the statement is bypassed
  • 5. Simple if - Example #include<stdio.h> #include<conio.h> int main() { int num1,num2; printf("Enter any two numbers "); scanf("%d %d",&num1,&num2); if(num1>num2) printf("nNum1 is greater than Num2"); printf("nEnd of program"); getch(); } Output1 Enter any two numbers 10 5 Num1 is greater than Num2 End of program Output1 Enter any two numbers 10 50 End of program
  • 6. IF Else Statement • An if statement can include an else clause that executes a statement or block if the boolean expression is not true. Syntax: If (condition) Statement1; Else Statement2; • If condition is true, then statement1 is executed. • Otherwise, statement2 is executed.
  • 7. if - else statement Syntax: if(condition) { True block statements; } else { False block statements; } if(condi tion) True Block Statement False True False Block Statements
  • 8. if – else Example # include <stdio.h> void main () { int num; printf ("Type a number:"); scanf ("%d", &num); if (number < 0) printf(“The number is negative”); else printf(“The number is positive”); } Output Type a number 50 The number is positive
  • 9. if – else Example #include<stdio.h> void main() { Int num; printf ("Enter a number:"); scanf ("%d",&num); if (num%2==0) printf ("The number is EVEN.n"); else printf ("The number is ODD.n"); } Output Enter a number 125 The number is ODD
  • 10. if – else Example #include<stdio.h> #include<conio.h> void main (void) { int percentage; printf(“Enter your percentage: “); scanf(“%d”, &percentage); if(percentage>=60) printf(“You are Passed”); else printf(“You are failed”); getch(); }
  • 11. Else - if Ladder Statement • An if statement can be followed by an optional else if...else statement, which is very useful to test various conditions using single if...else if statement. When using if , else if , else statements there are few points to keep in mind: • An if can have zero or one else's and it must come after any else if's. • An if can have zero to many else if's and they must come before the else. • Once an else if succeeds, none of the remaining else if's or else's will be tested.
  • 12. Else - if Ladder Statement Syntax if (condition1) statement block 1; else if (condition2) statement block 2; else if (condition3) statement block 3; : : else if (condition) statement block n; else default statement;
  • 13. Else - if Ladder Statement If(condition1) Default Statements; True False Statements1; Else if(condition2) True Statements2; False Else if(condition3) Statements3; False True
  • 14. Else - if Ladder Example #include<stdio.h> #include<conio.h> void main(void) { int num1,num2; clrscr(); printf(“Enter integer numbers to check: ”); scanf(“%d %d”,&num1,&num2); if(num1>num2) printf(“num1 is greater than num2”); else if(num1<num2) printf(“num1 is less than num2”); else printf(“both numbers are equal”); getch(); }
  • 15. Else - if Ladder Example #include <stdio.h> void main () { float perc; printf ("Enter Percentage:"); scanf ("%f", &perc); if (perc <= 100 && perc >= 80) printf ("n A-1 Grade"); else if (perc >= 70) printf("n A Grade"); else if (perc >= 60) printf ("n B Grade"); else printf ("Fail"); } Output Enter Percentage: 75 A Grade
  • 16. Else - if Ladder Example #include<stdio.h> #include<conio.h> int main() { float num1, num2; char op; printf("Enter two numbers"); scanf("%f %f",&num1,&num2); printf("nEnter operator (+,-,*,/)"); op=getche(); if(op =='+') printf("nResult=%f",num1+num2); else if(op == '-') printf("nResult=%f",num1-num2); else if(op == '*') printf("nResult=%f",num1*num2); else if(op == '/') printf("nResult=%f",num1/num2); else printf("Invalid Operator"); getch(); }