SlideShare ist ein Scribd-Unternehmen logo
1 von 16
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(); }

Weitere Àhnliche Inhalte

Was ist angesagt?

C statements
C statementsC statements
C statementsAhsann111
 
M C6java5
M C6java5M C6java5
M C6java5mbruggen
 
Decision control structures
Decision control structuresDecision control structures
Decision control structuresRahul Bathri
 
Selection statements
Selection statementsSelection statements
Selection statementsHarsh Dabas
 
M C6java6
M C6java6M C6java6
M C6java6mbruggen
 
The Three Basic Selection Structures in C++ Programming Concepts
The Three Basic Selection Structures in C++ Programming ConceptsThe Three Basic Selection Structures in C++ Programming Concepts
The Three Basic Selection Structures in C++ Programming ConceptsTech
 
Switch statement, break statement, go to statement
Switch statement, break statement, go to statementSwitch statement, break statement, go to statement
Switch statement, break statement, go to statementRaj Parekh
 
Java if else condition - powerpoint persentation
Java if else condition - powerpoint persentationJava if else condition - powerpoint persentation
Java if else condition - powerpoint persentationManeesha Caldera
 
Bsit1
Bsit1Bsit1
Bsit1jigeno
 
Cse lecture-6-c control statement
Cse lecture-6-c control statementCse lecture-6-c control statement
Cse lecture-6-c control statementFarshidKhan
 
java programming- control statements
 java programming- control statements java programming- control statements
java programming- control statementsjyoti_lakhani
 
Java Decision Control
Java Decision ControlJava Decision Control
Java Decision ControlJayfee Ramos
 
If statements in c programming
If statements in c programmingIf statements in c programming
If statements in c programmingArchana Gopinath
 
Cprogrammingprogramcontrols
CprogrammingprogramcontrolsCprogrammingprogramcontrols
Cprogrammingprogramcontrolsteach4uin
 
Constructs (Programming Methodology)
Constructs (Programming Methodology)Constructs (Programming Methodology)
Constructs (Programming Methodology)Jyoti Bhardwaj
 
Dti2143 chap 4 control structures aka_selection
Dti2143 chap 4 control structures aka_selectionDti2143 chap 4 control structures aka_selection
Dti2143 chap 4 control structures aka_selectionalish sha
 

Was ist angesagt? (20)

C statements
C statementsC statements
C statements
 
Control statement in c
Control statement in cControl statement in c
Control statement in c
 
M C6java5
M C6java5M C6java5
M C6java5
 
Decision control structures
Decision control structuresDecision control structures
Decision control structures
 
Selection statements
Selection statementsSelection statements
Selection statements
 
M C6java6
M C6java6M C6java6
M C6java6
 
The Three Basic Selection Structures in C++ Programming Concepts
The Three Basic Selection Structures in C++ Programming ConceptsThe Three Basic Selection Structures in C++ Programming Concepts
The Three Basic Selection Structures in C++ Programming Concepts
 
Chap 5(decision making-branching)
Chap 5(decision making-branching)Chap 5(decision making-branching)
Chap 5(decision making-branching)
 
Switch statement, break statement, go to statement
Switch statement, break statement, go to statementSwitch statement, break statement, go to statement
Switch statement, break statement, go to statement
 
C# conditional branching statement
C# conditional branching statementC# conditional branching statement
C# conditional branching statement
 
Java if else condition - powerpoint persentation
Java if else condition - powerpoint persentationJava if else condition - powerpoint persentation
Java if else condition - powerpoint persentation
 
Bsit1
Bsit1Bsit1
Bsit1
 
Cse lecture-6-c control statement
Cse lecture-6-c control statementCse lecture-6-c control statement
Cse lecture-6-c control statement
 
C Constructs (C Statements & Loop)
C Constructs (C Statements & Loop)C Constructs (C Statements & Loop)
C Constructs (C Statements & Loop)
 
java programming- control statements
 java programming- control statements java programming- control statements
java programming- control statements
 
Java Decision Control
Java Decision ControlJava Decision Control
Java Decision Control
 
If statements in c programming
If statements in c programmingIf statements in c programming
If statements in c programming
 
Cprogrammingprogramcontrols
CprogrammingprogramcontrolsCprogrammingprogramcontrols
Cprogrammingprogramcontrols
 
Constructs (Programming Methodology)
Constructs (Programming Methodology)Constructs (Programming Methodology)
Constructs (Programming Methodology)
 
Dti2143 chap 4 control structures aka_selection
Dti2143 chap 4 control structures aka_selectionDti2143 chap 4 control structures aka_selection
Dti2143 chap 4 control structures aka_selection
 

Andere mochten auch

Introduction of c_language
Introduction of c_languageIntroduction of c_language
Introduction of c_languageSINGH PROJECTS
 
Oops And C++ Fundamentals
Oops And C++ FundamentalsOops And C++ Fundamentals
Oops And C++ FundamentalsSubhasis Nayak
 
Data Structure in C Programming Language
Data Structure in C Programming LanguageData Structure in C Programming Language
Data Structure in C Programming LanguageArkadeep Dey
 
Lecture 2 history_of_c
Lecture 2 history_of_cLecture 2 history_of_c
Lecture 2 history_of_ceShikshak
 
C++ history session 00 history
C++ history session 00   historyC++ history session 00   history
C++ history session 00 historyArun Prakash
 
Victorian Crisis in Tennyson’s "Lotos Eaters"
Victorian Crisis in Tennyson’s "Lotos Eaters"Victorian Crisis in Tennyson’s "Lotos Eaters"
Victorian Crisis in Tennyson’s "Lotos Eaters"Nazmul Hetfield Batchu
 
Array in c language
Array in c languageArray in c language
Array in c languagehome
 
C Programming Language Tutorial for beginners - JavaTpoint
C Programming Language Tutorial for beginners - JavaTpointC Programming Language Tutorial for beginners - JavaTpoint
C Programming Language Tutorial for beginners - JavaTpointJavaTpoint.Com
 
INTRODUCTION TO C PROGRAMMING
INTRODUCTION TO C PROGRAMMINGINTRODUCTION TO C PROGRAMMING
INTRODUCTION TO C PROGRAMMINGAbhishek Dwivedi
 
History Of Computer
History Of ComputerHistory Of Computer
History Of Computerguest420b9d
 
Generations of computer
Generations of computerGenerations of computer
Generations of computerJatin Jindal
 
Basics of C programming
Basics of C programmingBasics of C programming
Basics of C programmingavikdhupar
 
Learning c - An extensive guide to learn the C Language
Learning c - An extensive guide to learn the C LanguageLearning c - An extensive guide to learn the C Language
Learning c - An extensive guide to learn the C LanguageAbhishek Dwivedi
 

Andere mochten auch (17)

Introduction of c_language
Introduction of c_languageIntroduction of c_language
Introduction of c_language
 
fundamentals of c
fundamentals of cfundamentals of c
fundamentals of c
 
Oops And C++ Fundamentals
Oops And C++ FundamentalsOops And C++ Fundamentals
Oops And C++ Fundamentals
 
Uses of computers
Uses of computersUses of computers
Uses of computers
 
Data Structure in C Programming Language
Data Structure in C Programming LanguageData Structure in C Programming Language
Data Structure in C Programming Language
 
Lecture 2 history_of_c
Lecture 2 history_of_cLecture 2 history_of_c
Lecture 2 history_of_c
 
C++ history session 00 history
C++ history session 00   historyC++ history session 00   history
C++ history session 00 history
 
Victorian Crisis in Tennyson’s "Lotos Eaters"
Victorian Crisis in Tennyson’s "Lotos Eaters"Victorian Crisis in Tennyson’s "Lotos Eaters"
Victorian Crisis in Tennyson’s "Lotos Eaters"
 
Computer History
Computer HistoryComputer History
Computer History
 
Array in c language
Array in c languageArray in c language
Array in c language
 
C Programming Language Tutorial for beginners - JavaTpoint
C Programming Language Tutorial for beginners - JavaTpointC Programming Language Tutorial for beginners - JavaTpoint
C Programming Language Tutorial for beginners - JavaTpoint
 
INTRODUCTION TO C PROGRAMMING
INTRODUCTION TO C PROGRAMMINGINTRODUCTION TO C PROGRAMMING
INTRODUCTION TO C PROGRAMMING
 
History Of Computer
History Of ComputerHistory Of Computer
History Of Computer
 
Generations of computer
Generations of computerGenerations of computer
Generations of computer
 
Basics of C programming
Basics of C programmingBasics of C programming
Basics of C programming
 
Learning c - An extensive guide to learn the C Language
Learning c - An extensive guide to learn the C LanguageLearning c - An extensive guide to learn the C Language
Learning c - An extensive guide to learn the C Language
 
GENERATION OF COMPUTERS.
GENERATION OF COMPUTERS.GENERATION OF COMPUTERS.
GENERATION OF COMPUTERS.
 

Ähnlich wie programming c language.

Decision Control Structure If & Else
Decision Control Structure If & ElseDecision Control Structure If & Else
Decision Control Structure If & ElseAbdullah Bhojani
 
Condition Stmt n Looping stmt.pptx
Condition Stmt n Looping stmt.pptxCondition Stmt n Looping stmt.pptx
Condition Stmt n Looping stmt.pptxLikhil181
 
Branching in C
Branching in CBranching in C
Branching in CPrabhu Govind
 
Dti2143 chap 4 control structures aka_selection
Dti2143 chap 4 control structures aka_selectionDti2143 chap 4 control structures aka_selection
Dti2143 chap 4 control structures aka_selectionalish sha
 
Programming Fundamentals Decisions
Programming Fundamentals  Decisions Programming Fundamentals  Decisions
Programming Fundamentals Decisions imtiazalijoono
 
Control Flow Statements
Control Flow Statements Control Flow Statements
Control Flow Statements Tarun Sharma
 
Loops and conditional statements
Loops and conditional statementsLoops and conditional statements
Loops and conditional statementsSaad Sheikh
 
Unit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in CUnit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in CSowmya Jyothi
 
unit 2-Control Structures.pptx
unit 2-Control Structures.pptxunit 2-Control Structures.pptx
unit 2-Control Structures.pptxishaparte4
 
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 FLOW in C.pptx
CONTROL FLOW in C.pptxCONTROL FLOW in C.pptx
CONTROL FLOW in C.pptxSmitaAparadh
 
CH-4 (1).pptx
CH-4 (1).pptxCH-4 (1).pptx
CH-4 (1).pptxMehul Desai
 
SPL 7 | Conditional Statements in C
SPL 7 | Conditional Statements in CSPL 7 | Conditional Statements in C
SPL 7 | Conditional Statements in CMohammad Imam Hossain
 

Ähnlich wie programming c language. (20)

Decision Control Structure If & Else
Decision Control Structure If & ElseDecision Control Structure If & Else
Decision Control Structure If & Else
 
Condition Stmt n Looping stmt.pptx
Condition Stmt n Looping stmt.pptxCondition Stmt n Looping stmt.pptx
Condition Stmt n Looping stmt.pptx
 
Branching in C
Branching in CBranching in C
Branching in C
 
Dti2143 chap 4 control structures aka_selection
Dti2143 chap 4 control structures aka_selectionDti2143 chap 4 control structures aka_selection
Dti2143 chap 4 control structures aka_selection
 
control statement
control statement control statement
control statement
 
Programming Fundamentals Decisions
Programming Fundamentals  Decisions Programming Fundamentals  Decisions
Programming Fundamentals Decisions
 
Control Flow Statements
Control Flow Statements Control Flow Statements
Control Flow Statements
 
Loops and conditional statements
Loops and conditional statementsLoops and conditional statements
Loops and conditional statements
 
Control statement-Selective
Control statement-SelectiveControl statement-Selective
Control statement-Selective
 
Unit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in CUnit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in C
 
unit 2-Control Structures.pptx
unit 2-Control Structures.pptxunit 2-Control Structures.pptx
unit 2-Control Structures.pptx
 
Fundamental of Information Technology - UNIT 8
Fundamental of Information Technology - UNIT 8Fundamental of Information Technology - UNIT 8
Fundamental of Information Technology - UNIT 8
 
CONTROL FLOW in C.pptx
CONTROL FLOW in C.pptxCONTROL FLOW in C.pptx
CONTROL FLOW in C.pptx
 
L3 control
L3 controlL3 control
L3 control
 
CH-4 (1).pptx
CH-4 (1).pptxCH-4 (1).pptx
CH-4 (1).pptx
 
Session 3
Session 3Session 3
Session 3
 
conditional_statement.pdf
conditional_statement.pdfconditional_statement.pdf
conditional_statement.pdf
 
if,loop,switch
if,loop,switchif,loop,switch
if,loop,switch
 
Control structures in c
Control structures in cControl structures in c
Control structures in c
 
SPL 7 | Conditional Statements in C
SPL 7 | Conditional Statements in CSPL 7 | Conditional Statements in C
SPL 7 | Conditional Statements in C
 

Mehr von Abdul Rehman

Introduction Relational Marketing
Introduction Relational Marketing Introduction Relational Marketing
Introduction Relational Marketing Abdul Rehman
 
Software Engineering
Software Engineering Software Engineering
Software Engineering Abdul Rehman
 
Introduction To Autumata Theory
 Introduction To Autumata Theory Introduction To Autumata Theory
Introduction To Autumata TheoryAbdul Rehman
 
Query optimization in SQL
Query optimization in SQLQuery optimization in SQL
Query optimization in SQLAbdul Rehman
 
computer System UNit Every thing
computer System UNit Every thingcomputer System UNit Every thing
computer System UNit Every thingAbdul Rehman
 
Education system in Pakistan
Education system in PakistanEducation system in Pakistan
Education system in PakistanAbdul Rehman
 
How to write a letter
How to write a letterHow to write a letter
How to write a letterAbdul Rehman
 
Writing good paragraphs ppt
Writing good paragraphs pptWriting good paragraphs ppt
Writing good paragraphs pptAbdul Rehman
 

Mehr von Abdul Rehman (8)

Introduction Relational Marketing
Introduction Relational Marketing Introduction Relational Marketing
Introduction Relational Marketing
 
Software Engineering
Software Engineering Software Engineering
Software Engineering
 
Introduction To Autumata Theory
 Introduction To Autumata Theory Introduction To Autumata Theory
Introduction To Autumata Theory
 
Query optimization in SQL
Query optimization in SQLQuery optimization in SQL
Query optimization in SQL
 
computer System UNit Every thing
computer System UNit Every thingcomputer System UNit Every thing
computer System UNit Every thing
 
Education system in Pakistan
Education system in PakistanEducation system in Pakistan
Education system in Pakistan
 
How to write a letter
How to write a letterHow to write a letter
How to write a letter
 
Writing good paragraphs ppt
Writing good paragraphs pptWriting good paragraphs ppt
Writing good paragraphs ppt
 

KĂŒrzlich hochgeladen

CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceBrainSell Technologies
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Angel Borroy LĂłpez
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Natan Silnitsky
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf31events.com
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...OnePlan Solutions
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfMarharyta Nedzelska
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsSafe Software
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Cizo Technology Services
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commercemanigoyal112
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationBradBedford3
 
Call Us🔝>àŒ’+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>àŒ’+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>àŒ’+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>àŒ’+91-9711147426⇛Call In girls karol bagh (Delhi)jennyeacort
 
VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Developmentvyaparkranti
 
Post Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on IdentityPost Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on Identityteam-WIBU
 
Large Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLarge Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLionel Briand
 
Patterns for automating API delivery. API conference
Patterns for automating API delivery. API conferencePatterns for automating API delivery. API conference
Patterns for automating API delivery. API conferencessuser9e7c64
 
Advantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your BusinessAdvantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your BusinessEnvertis Software Solutions
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...Technogeeks
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfDrew Moseley
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...confluent
 

KĂŒrzlich hochgeladen (20)

CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. Salesforce
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdf
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data Streams
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commerce
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion Application
 
Call Us🔝>àŒ’+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>àŒ’+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>àŒ’+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>àŒ’+91-9711147426⇛Call In girls karol bagh (Delhi)
 
VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Development
 
Post Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on IdentityPost Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on Identity
 
Large Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLarge Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and Repair
 
Patterns for automating API delivery. API conference
Patterns for automating API delivery. API conferencePatterns for automating API delivery. API conference
Patterns for automating API delivery. API conference
 
Advantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your BusinessAdvantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your Business
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdf
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
 

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(); }