SlideShare a Scribd company logo
2
Brief flow of presentation
1. Introduction
2. Simple if else statement
3. Nesting of if else statement
4. Else if Ladder
Most read
9
Nested if else if Flow Chart
if (<test>) {
<statement(s)>;
} else if (<test>) {
<statement(s)>;
} else if (<test>) {
<statement(s)>;
}
9
Most read
11
The else if ladder
falsetrue
true false
false
false
test
condition1
statement-nn default
statement
statement-1
statement-2
true
true
Entry
statement-3
statement-x
test
condition1
test
condition3
test
condition-n
11
Most read
Gandhinagar Institute
of Technology(012)
Subject : CPU (2110003)
Active Learning Assignment
Branch : Computer
DIV. : A-2
Prepared by : - Vishvesh jasani (160120107042)
Guided By: Prof. Nirav Pandya
topic:Nesting of if else statement & Else If Ladder
Brief flow of presentation
1. Introduction
2. Simple if else statement
3. Nesting of if else statement
4. Else if Ladder
The if else Statement
if else statement: A control structure that executes one block of
statements if a certain condition is true, and a second block of
statements if it is false. We refer to each block as a branch.
General syntax:
if (<test>) {
<statement(s)> ;
} else {
<statement(s)> ;
}
Example:
#include<stdio.h>
int main()
{
int number;
printf("Enter an integer: ");
scanf("%d",&number);
Flow chart
// 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;
}
Output:
Enter an integer: 7
7 is an odd integer
Output
Nested if...else statement
-The if...else statement executes two different codes depending
upon whether the test expression is true or false.
- Sometimes, a choice has to be made from more than 2
possibilities.
-The nested if...else statement allows you to check for multiple test
expressions and execute different codes for more than two
conditions.
Syntax of nested if...else statement
if (testExpression1)
{
// statements to be executed if testExpression1 is true
}
else if(testExpression2)
{
// statements to be executed if testExpression1 is false and testExpression2 is true
}
else if (testExpression 3)
{
// statements to be executed if testExpression1 and testExpression2 is false and testExpression3 is
true
}
.
else
{
// statements to be executed if all test expressions are false
Example
#include <stdio.h>
int main()
{
int number1, number2;
printf("Enter two integers: ");
scanf("%d %d", &number1, &number2);
//checks if two integers are equal.
if(number1 == number2)
{
printf("Result: %d = %d",number1,number2);
}
//checks if number1 is greater than number2.
else if (number1 > number2)
{
printf("Result: %d > %d", number1, number2);
}
// if both test expression is false
else
{
printf("Result: %d < %d",number1, number2);
}
return 0;
}
Output:
Enter two integers: 12
23
Result: 12 < 23
Nested if else if Flow Chart
if (<test>) {
<statement(s)>;
} else if (<test>) {
<statement(s)>;
} else if (<test>) {
<statement(s)>;
}
9
The else if ladder
if ( test condition-1 )
statement-1
else if ( test condition-2 )
statement-2;
else if (condition-3)
statement-3;
else if ( condition-n)
statement-n;
else
default-statement;
statement-x;
10
The else if ladder
falsetrue
true false
false
false
test
condition1
statement-nn default
statement
statement-1
statement-2
true
true
Entry
statement-3
statement-x
test
condition1
test
condition3
test
condition-n
11
Example
main()
{
int units, custnum;
float charges;
printf("Enter customer no. and units consumedn");
scanf("%d%d",&custnum,&units);
if(units<=200)
charges=0.5*units;
else if(units<=400)
charges=100+0.65*(units-200);
else if(units<=600)
charges=230+0.8*(units-400);
else
charges=390+(units-600);
printf("nnCustomer no:%d Charge=%.2fn", custnum, charges );
}
Nesting of if else statement & Else If Ladder

More Related Content

What's hot (20)

Control statements in c
Control statements in cControl statements in c
Control statements in c
Sathish Narayanan
 
C if else
C if elseC if else
C if else
Ritwik Das
 
Strings
StringsStrings
Strings
Mitali Chugh
 
Strings in C
Strings in CStrings in C
Strings in C
Kamal Acharya
 
Control Statement programming
Control Statement programmingControl Statement programming
Control Statement programming
University of Potsdam
 
Decision making statements in C programming
Decision making statements in C programmingDecision making statements in C programming
Decision making statements in C programming
Rabin BK
 
Python programming : Control statements
Python programming : Control statementsPython programming : Control statements
Python programming : Control statements
Emertxe Information Technologies Pvt Ltd
 
RECURSION IN C
RECURSION IN C RECURSION IN C
RECURSION IN C
v_jk
 
Decision Making Statement in C ppt
Decision Making Statement in C pptDecision Making Statement in C ppt
Decision Making Statement in C ppt
MANJUTRIPATHI7
 
C Programming: Control Structure
C Programming: Control StructureC Programming: Control Structure
C Programming: Control Structure
Sokngim Sa
 
Conditional Statement in C Language
Conditional Statement in C LanguageConditional Statement in C Language
Conditional Statement in C Language
Shaina Arora
 
Loops in C Programming Language
Loops in C Programming LanguageLoops in C Programming Language
Loops in C Programming Language
Mahantesh Devoor
 
Pointer in c
Pointer in cPointer in c
Pointer in c
lavanya marichamy
 
Control Flow Statements
Control Flow Statements Control Flow Statements
Control Flow Statements
Tarun Sharma
 
Data Types and Variables In C Programming
Data Types and Variables In C ProgrammingData Types and Variables In C Programming
Data Types and Variables In C Programming
Kamal Acharya
 
Functions in C
Functions in CFunctions in C
Functions in C
Kamal Acharya
 
Branching statements
Branching statementsBranching statements
Branching statements
ArunMK17
 
C functions
C functionsC functions
C functions
University of Potsdam
 
10. switch case
10. switch case10. switch case
10. switch case
Way2itech
 
Decision making and branching in c programming
Decision making and branching in c programmingDecision making and branching in c programming
Decision making and branching in c programming
Priyansh Thakar
 
Decision making statements in C programming
Decision making statements in C programmingDecision making statements in C programming
Decision making statements in C programming
Rabin BK
 
RECURSION IN C
RECURSION IN C RECURSION IN C
RECURSION IN C
v_jk
 
Decision Making Statement in C ppt
Decision Making Statement in C pptDecision Making Statement in C ppt
Decision Making Statement in C ppt
MANJUTRIPATHI7
 
C Programming: Control Structure
C Programming: Control StructureC Programming: Control Structure
C Programming: Control Structure
Sokngim Sa
 
Conditional Statement in C Language
Conditional Statement in C LanguageConditional Statement in C Language
Conditional Statement in C Language
Shaina Arora
 
Loops in C Programming Language
Loops in C Programming LanguageLoops in C Programming Language
Loops in C Programming Language
Mahantesh Devoor
 
Control Flow Statements
Control Flow Statements Control Flow Statements
Control Flow Statements
Tarun Sharma
 
Data Types and Variables In C Programming
Data Types and Variables In C ProgrammingData Types and Variables In C Programming
Data Types and Variables In C Programming
Kamal Acharya
 
Branching statements
Branching statementsBranching statements
Branching statements
ArunMK17
 
10. switch case
10. switch case10. switch case
10. switch case
Way2itech
 
Decision making and branching in c programming
Decision making and branching in c programmingDecision making and branching in c programming
Decision making and branching in c programming
Priyansh Thakar
 

Similar to Nesting of if else statement & Else If Ladder (20)

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
Moni Adhikary
 
Conditional statements
Conditional statementsConditional statements
Conditional statements
NabishaAK
 
Selection structure
Selection structureSelection structure
Selection structure
Jyoti Pokharna
 
175035 cse lab-03
175035 cse lab-03175035 cse lab-03
175035 cse lab-03
Mahbubay Rabbani Mim
 
Structured Programming Unit-5-Control-Structure.pptx
Structured Programming  Unit-5-Control-Structure.pptxStructured Programming  Unit-5-Control-Structure.pptx
Structured Programming Unit-5-Control-Structure.pptx
SuryaBasnet1
 
Decision making using if statement
Decision making using if statementDecision making using if statement
Decision making using if statement
CHANDAN KUMAR
 
C Programming: Control Statements in C Pgm
C Programming: Control Statements in C PgmC Programming: Control Statements in C Pgm
C Programming: Control Statements in C Pgm
Navya Francis
 
Unit-2 control Structures.pptx.pptx20201
Unit-2 control Structures.pptx.pptx20201Unit-2 control Structures.pptx.pptx20201
Unit-2 control Structures.pptx.pptx20201
vpenubot
 
Decision Control Structure If & Else
Decision Control Structure If & ElseDecision Control Structure If & Else
Decision Control Structure If & Else
Abdullah Bhojani
 
control-statements in C Language MH.pptx
control-statements in C Language MH.pptxcontrol-statements in C Language MH.pptx
control-statements in C Language MH.pptx
mehedi_hasan
 
CH-4 (1).pptx
CH-4 (1).pptxCH-4 (1).pptx
CH-4 (1).pptx
Mehul Desai
 
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
Sowmya Jyothi
 
SPL 7 | Conditional Statements in C
SPL 7 | Conditional Statements in CSPL 7 | Conditional Statements in C
SPL 7 | Conditional Statements in C
Mohammad Imam Hossain
 
6 Control Structures-1.pptxAAAAAAAAAAAAAAAAAAAAA
6 Control Structures-1.pptxAAAAAAAAAAAAAAAAAAAAA6 Control Structures-1.pptxAAAAAAAAAAAAAAAAAAAAA
6 Control Structures-1.pptxAAAAAAAAAAAAAAAAAAAAA
EG20910848921ISAACDU
 
Control Statements -if else in C programming.pptx
Control Statements -if else in C programming.pptxControl Statements -if else in C programming.pptx
Control Statements -if else in C programming.pptx
ganeshmahato20
 
C Control Statements.docx
C Control Statements.docxC Control Statements.docx
C Control Statements.docx
JavvajiVenkat
 
Introduction to computer programming (C)-CSC1205_Lec5_Flow control
Introduction to computer programming (C)-CSC1205_Lec5_Flow controlIntroduction to computer programming (C)-CSC1205_Lec5_Flow control
Introduction to computer programming (C)-CSC1205_Lec5_Flow control
ENGWAU TONNY
 
Control structures in c
Control structures in cControl structures in c
Control structures in c
baabtra.com - No. 1 supplier of quality freshers
 
Lec16.pptx problem specifications computer
Lec16.pptx problem specifications computerLec16.pptx problem specifications computer
Lec16.pptx problem specifications computer
samiullahamjad06
 
control-statements detailed presentation
control-statements detailed presentationcontrol-statements detailed presentation
control-statements detailed presentation
gayathripcs
 
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
Moni Adhikary
 
Conditional statements
Conditional statementsConditional statements
Conditional statements
NabishaAK
 
Structured Programming Unit-5-Control-Structure.pptx
Structured Programming  Unit-5-Control-Structure.pptxStructured Programming  Unit-5-Control-Structure.pptx
Structured Programming Unit-5-Control-Structure.pptx
SuryaBasnet1
 
Decision making using if statement
Decision making using if statementDecision making using if statement
Decision making using if statement
CHANDAN KUMAR
 
C Programming: Control Statements in C Pgm
C Programming: Control Statements in C PgmC Programming: Control Statements in C Pgm
C Programming: Control Statements in C Pgm
Navya Francis
 
Unit-2 control Structures.pptx.pptx20201
Unit-2 control Structures.pptx.pptx20201Unit-2 control Structures.pptx.pptx20201
Unit-2 control Structures.pptx.pptx20201
vpenubot
 
Decision Control Structure If & Else
Decision Control Structure If & ElseDecision Control Structure If & Else
Decision Control Structure If & Else
Abdullah Bhojani
 
control-statements in C Language MH.pptx
control-statements in C Language MH.pptxcontrol-statements in C Language MH.pptx
control-statements in C Language MH.pptx
mehedi_hasan
 
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
Sowmya Jyothi
 
6 Control Structures-1.pptxAAAAAAAAAAAAAAAAAAAAA
6 Control Structures-1.pptxAAAAAAAAAAAAAAAAAAAAA6 Control Structures-1.pptxAAAAAAAAAAAAAAAAAAAAA
6 Control Structures-1.pptxAAAAAAAAAAAAAAAAAAAAA
EG20910848921ISAACDU
 
Control Statements -if else in C programming.pptx
Control Statements -if else in C programming.pptxControl Statements -if else in C programming.pptx
Control Statements -if else in C programming.pptx
ganeshmahato20
 
C Control Statements.docx
C Control Statements.docxC Control Statements.docx
C Control Statements.docx
JavvajiVenkat
 
Introduction to computer programming (C)-CSC1205_Lec5_Flow control
Introduction to computer programming (C)-CSC1205_Lec5_Flow controlIntroduction to computer programming (C)-CSC1205_Lec5_Flow control
Introduction to computer programming (C)-CSC1205_Lec5_Flow control
ENGWAU TONNY
 
Lec16.pptx problem specifications computer
Lec16.pptx problem specifications computerLec16.pptx problem specifications computer
Lec16.pptx problem specifications computer
samiullahamjad06
 
control-statements detailed presentation
control-statements detailed presentationcontrol-statements detailed presentation
control-statements detailed presentation
gayathripcs
 
Ad

More from Vishvesh Jasani (9)

Row space | Column Space | Null space | Rank | Nullity
Row space | Column Space | Null space | Rank | NullityRow space | Column Space | Null space | Rank | Nullity
Row space | Column Space | Null space | Rank | Nullity
Vishvesh Jasani
 
Air Pollution Control act
Air Pollution Control actAir Pollution Control act
Air Pollution Control act
Vishvesh Jasani
 
Types Of Reciprocating Member of the Pump
Types Of Reciprocating Member of the PumpTypes Of Reciprocating Member of the Pump
Types Of Reciprocating Member of the Pump
Vishvesh Jasani
 
Projection Of Plane
Projection Of PlaneProjection Of Plane
Projection Of Plane
Vishvesh Jasani
 
Summing Amplifer
Summing AmpliferSumming Amplifer
Summing Amplifer
Vishvesh Jasani
 
Advantages of OPTICAL FIBER CABLE
Advantages of OPTICAL FIBER CABLEAdvantages of OPTICAL FIBER CABLE
Advantages of OPTICAL FIBER CABLE
Vishvesh Jasani
 
Definitons-Electric Field,Lines of Force,Electric Intensity
Definitons-Electric Field,Lines of Force,Electric Intensity Definitons-Electric Field,Lines of Force,Electric Intensity
Definitons-Electric Field,Lines of Force,Electric Intensity
Vishvesh Jasani
 
Difference between Hearing & Listening,Types of Listening ...
Difference between Hearing & Listening,Types of Listening                    ...Difference between Hearing & Listening,Types of Listening                    ...
Difference between Hearing & Listening,Types of Listening ...
Vishvesh Jasani
 
Continuity of a Function
Continuity of a Function Continuity of a Function
Continuity of a Function
Vishvesh Jasani
 
Row space | Column Space | Null space | Rank | Nullity
Row space | Column Space | Null space | Rank | NullityRow space | Column Space | Null space | Rank | Nullity
Row space | Column Space | Null space | Rank | Nullity
Vishvesh Jasani
 
Air Pollution Control act
Air Pollution Control actAir Pollution Control act
Air Pollution Control act
Vishvesh Jasani
 
Types Of Reciprocating Member of the Pump
Types Of Reciprocating Member of the PumpTypes Of Reciprocating Member of the Pump
Types Of Reciprocating Member of the Pump
Vishvesh Jasani
 
Advantages of OPTICAL FIBER CABLE
Advantages of OPTICAL FIBER CABLEAdvantages of OPTICAL FIBER CABLE
Advantages of OPTICAL FIBER CABLE
Vishvesh Jasani
 
Definitons-Electric Field,Lines of Force,Electric Intensity
Definitons-Electric Field,Lines of Force,Electric Intensity Definitons-Electric Field,Lines of Force,Electric Intensity
Definitons-Electric Field,Lines of Force,Electric Intensity
Vishvesh Jasani
 
Difference between Hearing & Listening,Types of Listening ...
Difference between Hearing & Listening,Types of Listening                    ...Difference between Hearing & Listening,Types of Listening                    ...
Difference between Hearing & Listening,Types of Listening ...
Vishvesh Jasani
 
Continuity of a Function
Continuity of a Function Continuity of a Function
Continuity of a Function
Vishvesh Jasani
 
Ad

Recently uploaded (20)

LET´S PRACTICE GRAMMAR USING SIMPLE PAST TENSE
LET´S PRACTICE GRAMMAR USING SIMPLE PAST TENSELET´S PRACTICE GRAMMAR USING SIMPLE PAST TENSE
LET´S PRACTICE GRAMMAR USING SIMPLE PAST TENSE
OlgaLeonorTorresSnch
 
Diana Enriquez Wauconda - A Wauconda-Based Educator
Diana Enriquez Wauconda - A Wauconda-Based EducatorDiana Enriquez Wauconda - A Wauconda-Based Educator
Diana Enriquez Wauconda - A Wauconda-Based Educator
Diana Enriquez Wauconda
 
POS Reporting in Odoo 18 - Odoo 18 Slides
POS Reporting in Odoo 18 - Odoo 18 SlidesPOS Reporting in Odoo 18 - Odoo 18 Slides
POS Reporting in Odoo 18 - Odoo 18 Slides
Celine George
 
Order Lepidoptera: Butterflies and Moths.pptx
Order Lepidoptera: Butterflies and Moths.pptxOrder Lepidoptera: Butterflies and Moths.pptx
Order Lepidoptera: Butterflies and Moths.pptx
Arshad Shaikh
 
Odoo 18 Point of Sale PWA - Odoo Slides
Odoo 18 Point of Sale PWA  - Odoo  SlidesOdoo 18 Point of Sale PWA  - Odoo  Slides
Odoo 18 Point of Sale PWA - Odoo Slides
Celine George
 
Writing Research Papers: Guidance for Research Community
Writing Research Papers: Guidance for Research CommunityWriting Research Papers: Guidance for Research Community
Writing Research Papers: Guidance for Research Community
Rishi Bankim Chandra Evening College, Naihati, North 24 Parganas, West Bengal, India
 
How to Use Owl Slots in Odoo 17 - Odoo Slides
How to Use Owl Slots in Odoo 17 - Odoo SlidesHow to Use Owl Slots in Odoo 17 - Odoo Slides
How to Use Owl Slots in Odoo 17 - Odoo Slides
Celine George
 
"Dictyoptera: The Order of Cockroaches and Mantises" Or, more specifically: ...
"Dictyoptera: The Order of Cockroaches and Mantises"  Or, more specifically: ..."Dictyoptera: The Order of Cockroaches and Mantises"  Or, more specifically: ...
"Dictyoptera: The Order of Cockroaches and Mantises" Or, more specifically: ...
Arshad Shaikh
 
"Hymenoptera: A Diverse and Fascinating Order".pptx
"Hymenoptera: A Diverse and Fascinating Order".pptx"Hymenoptera: A Diverse and Fascinating Order".pptx
"Hymenoptera: A Diverse and Fascinating Order".pptx
Arshad Shaikh
 
Forestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdf
Forestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdfForestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdf
Forestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdf
ChalaKelbessa
 
How to Setup Renewal of Subscription in Odoo 18
How to Setup Renewal of Subscription in Odoo 18How to Setup Renewal of Subscription in Odoo 18
How to Setup Renewal of Subscription in Odoo 18
Celine George
 
প্রত্যুৎপন্নমতিত্ব - Prottutponnomotittwa 2025.pdf
প্রত্যুৎপন্নমতিত্ব - Prottutponnomotittwa 2025.pdfপ্রত্যুৎপন্নমতিত্ব - Prottutponnomotittwa 2025.pdf
প্রত্যুৎপন্নমতিত্ব - Prottutponnomotittwa 2025.pdf
Pragya - UEM Kolkata Quiz Club
 
HUMAN SKELETAL SYSTEM ANATAMY AND PHYSIOLOGY
HUMAN SKELETAL SYSTEM ANATAMY AND PHYSIOLOGYHUMAN SKELETAL SYSTEM ANATAMY AND PHYSIOLOGY
HUMAN SKELETAL SYSTEM ANATAMY AND PHYSIOLOGY
DHARMENDRA SAHU
 
How to Manage Orders in Odoo 18 Lunch - Odoo Slides
How to Manage Orders in Odoo 18 Lunch - Odoo SlidesHow to Manage Orders in Odoo 18 Lunch - Odoo Slides
How to Manage Orders in Odoo 18 Lunch - Odoo Slides
Celine George
 
Cloud Computing ..PPT ( Faizan ALTAF )..
Cloud Computing ..PPT ( Faizan ALTAF )..Cloud Computing ..PPT ( Faizan ALTAF )..
Cloud Computing ..PPT ( Faizan ALTAF )..
faizanaltaf231
 
CBSE - Grade 11 - Mathematics - Ch 2 - Relations And Functions - Notes (PDF F...
CBSE - Grade 11 - Mathematics - Ch 2 - Relations And Functions - Notes (PDF F...CBSE - Grade 11 - Mathematics - Ch 2 - Relations And Functions - Notes (PDF F...
CBSE - Grade 11 - Mathematics - Ch 2 - Relations And Functions - Notes (PDF F...
Sritoma Majumder
 
THE CHURCH AND ITS IMPACT: FOSTERING CHRISTIAN EDUCATION
THE CHURCH AND ITS IMPACT: FOSTERING CHRISTIAN EDUCATIONTHE CHURCH AND ITS IMPACT: FOSTERING CHRISTIAN EDUCATION
THE CHURCH AND ITS IMPACT: FOSTERING CHRISTIAN EDUCATION
PROF. PAUL ALLIEU KAMARA
 
How to Create Time Off Request in Odoo 18 Time Off
How to Create Time Off Request in Odoo 18 Time OffHow to Create Time Off Request in Odoo 18 Time Off
How to Create Time Off Request in Odoo 18 Time Off
Celine George
 
0b - THE ROMANTIC ERA: FEELINGS AND IDENTITY.pptx
0b - THE ROMANTIC ERA: FEELINGS AND IDENTITY.pptx0b - THE ROMANTIC ERA: FEELINGS AND IDENTITY.pptx
0b - THE ROMANTIC ERA: FEELINGS AND IDENTITY.pptx
Julián Jesús Pérez Fernández
 
Coleoptera: The Largest Insect Order.pptx
Coleoptera: The Largest Insect Order.pptxColeoptera: The Largest Insect Order.pptx
Coleoptera: The Largest Insect Order.pptx
Arshad Shaikh
 
LET´S PRACTICE GRAMMAR USING SIMPLE PAST TENSE
LET´S PRACTICE GRAMMAR USING SIMPLE PAST TENSELET´S PRACTICE GRAMMAR USING SIMPLE PAST TENSE
LET´S PRACTICE GRAMMAR USING SIMPLE PAST TENSE
OlgaLeonorTorresSnch
 
Diana Enriquez Wauconda - A Wauconda-Based Educator
Diana Enriquez Wauconda - A Wauconda-Based EducatorDiana Enriquez Wauconda - A Wauconda-Based Educator
Diana Enriquez Wauconda - A Wauconda-Based Educator
Diana Enriquez Wauconda
 
POS Reporting in Odoo 18 - Odoo 18 Slides
POS Reporting in Odoo 18 - Odoo 18 SlidesPOS Reporting in Odoo 18 - Odoo 18 Slides
POS Reporting in Odoo 18 - Odoo 18 Slides
Celine George
 
Order Lepidoptera: Butterflies and Moths.pptx
Order Lepidoptera: Butterflies and Moths.pptxOrder Lepidoptera: Butterflies and Moths.pptx
Order Lepidoptera: Butterflies and Moths.pptx
Arshad Shaikh
 
Odoo 18 Point of Sale PWA - Odoo Slides
Odoo 18 Point of Sale PWA  - Odoo  SlidesOdoo 18 Point of Sale PWA  - Odoo  Slides
Odoo 18 Point of Sale PWA - Odoo Slides
Celine George
 
How to Use Owl Slots in Odoo 17 - Odoo Slides
How to Use Owl Slots in Odoo 17 - Odoo SlidesHow to Use Owl Slots in Odoo 17 - Odoo Slides
How to Use Owl Slots in Odoo 17 - Odoo Slides
Celine George
 
"Dictyoptera: The Order of Cockroaches and Mantises" Or, more specifically: ...
"Dictyoptera: The Order of Cockroaches and Mantises"  Or, more specifically: ..."Dictyoptera: The Order of Cockroaches and Mantises"  Or, more specifically: ...
"Dictyoptera: The Order of Cockroaches and Mantises" Or, more specifically: ...
Arshad Shaikh
 
"Hymenoptera: A Diverse and Fascinating Order".pptx
"Hymenoptera: A Diverse and Fascinating Order".pptx"Hymenoptera: A Diverse and Fascinating Order".pptx
"Hymenoptera: A Diverse and Fascinating Order".pptx
Arshad Shaikh
 
Forestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdf
Forestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdfForestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdf
Forestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdf
ChalaKelbessa
 
How to Setup Renewal of Subscription in Odoo 18
How to Setup Renewal of Subscription in Odoo 18How to Setup Renewal of Subscription in Odoo 18
How to Setup Renewal of Subscription in Odoo 18
Celine George
 
প্রত্যুৎপন্নমতিত্ব - Prottutponnomotittwa 2025.pdf
প্রত্যুৎপন্নমতিত্ব - Prottutponnomotittwa 2025.pdfপ্রত্যুৎপন্নমতিত্ব - Prottutponnomotittwa 2025.pdf
প্রত্যুৎপন্নমতিত্ব - Prottutponnomotittwa 2025.pdf
Pragya - UEM Kolkata Quiz Club
 
HUMAN SKELETAL SYSTEM ANATAMY AND PHYSIOLOGY
HUMAN SKELETAL SYSTEM ANATAMY AND PHYSIOLOGYHUMAN SKELETAL SYSTEM ANATAMY AND PHYSIOLOGY
HUMAN SKELETAL SYSTEM ANATAMY AND PHYSIOLOGY
DHARMENDRA SAHU
 
How to Manage Orders in Odoo 18 Lunch - Odoo Slides
How to Manage Orders in Odoo 18 Lunch - Odoo SlidesHow to Manage Orders in Odoo 18 Lunch - Odoo Slides
How to Manage Orders in Odoo 18 Lunch - Odoo Slides
Celine George
 
Cloud Computing ..PPT ( Faizan ALTAF )..
Cloud Computing ..PPT ( Faizan ALTAF )..Cloud Computing ..PPT ( Faizan ALTAF )..
Cloud Computing ..PPT ( Faizan ALTAF )..
faizanaltaf231
 
CBSE - Grade 11 - Mathematics - Ch 2 - Relations And Functions - Notes (PDF F...
CBSE - Grade 11 - Mathematics - Ch 2 - Relations And Functions - Notes (PDF F...CBSE - Grade 11 - Mathematics - Ch 2 - Relations And Functions - Notes (PDF F...
CBSE - Grade 11 - Mathematics - Ch 2 - Relations And Functions - Notes (PDF F...
Sritoma Majumder
 
THE CHURCH AND ITS IMPACT: FOSTERING CHRISTIAN EDUCATION
THE CHURCH AND ITS IMPACT: FOSTERING CHRISTIAN EDUCATIONTHE CHURCH AND ITS IMPACT: FOSTERING CHRISTIAN EDUCATION
THE CHURCH AND ITS IMPACT: FOSTERING CHRISTIAN EDUCATION
PROF. PAUL ALLIEU KAMARA
 
How to Create Time Off Request in Odoo 18 Time Off
How to Create Time Off Request in Odoo 18 Time OffHow to Create Time Off Request in Odoo 18 Time Off
How to Create Time Off Request in Odoo 18 Time Off
Celine George
 
Coleoptera: The Largest Insect Order.pptx
Coleoptera: The Largest Insect Order.pptxColeoptera: The Largest Insect Order.pptx
Coleoptera: The Largest Insect Order.pptx
Arshad Shaikh
 

Nesting of if else statement & Else If Ladder

  • 1. Gandhinagar Institute of Technology(012) Subject : CPU (2110003) Active Learning Assignment Branch : Computer DIV. : A-2 Prepared by : - Vishvesh jasani (160120107042) Guided By: Prof. Nirav Pandya topic:Nesting of if else statement & Else If Ladder
  • 2. Brief flow of presentation 1. Introduction 2. Simple if else statement 3. Nesting of if else statement 4. Else if Ladder
  • 3. The if else Statement if else statement: A control structure that executes one block of statements if a certain condition is true, and a second block of statements if it is false. We refer to each block as a branch. General syntax: if (<test>) { <statement(s)> ; } else { <statement(s)> ; } Example: #include<stdio.h> int main() { int number; printf("Enter an integer: "); scanf("%d",&number);
  • 4. Flow chart // 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; } Output: Enter an integer: 7 7 is an odd integer Output
  • 5. Nested if...else statement -The if...else statement executes two different codes depending upon whether the test expression is true or false. - Sometimes, a choice has to be made from more than 2 possibilities. -The nested if...else statement allows you to check for multiple test expressions and execute different codes for more than two conditions.
  • 6. Syntax of nested if...else statement if (testExpression1) { // statements to be executed if testExpression1 is true } else if(testExpression2) { // statements to be executed if testExpression1 is false and testExpression2 is true } else if (testExpression 3) { // statements to be executed if testExpression1 and testExpression2 is false and testExpression3 is true } . else { // statements to be executed if all test expressions are false
  • 7. Example #include <stdio.h> int main() { int number1, number2; printf("Enter two integers: "); scanf("%d %d", &number1, &number2); //checks if two integers are equal. if(number1 == number2) { printf("Result: %d = %d",number1,number2); } //checks if number1 is greater than number2. else if (number1 > number2) { printf("Result: %d > %d", number1, number2); }
  • 8. // if both test expression is false else { printf("Result: %d < %d",number1, number2); } return 0; } Output: Enter two integers: 12 23 Result: 12 < 23
  • 9. Nested if else if Flow Chart if (<test>) { <statement(s)>; } else if (<test>) { <statement(s)>; } else if (<test>) { <statement(s)>; } 9
  • 10. The else if ladder if ( test condition-1 ) statement-1 else if ( test condition-2 ) statement-2; else if (condition-3) statement-3; else if ( condition-n) statement-n; else default-statement; statement-x; 10
  • 11. The else if ladder falsetrue true false false false test condition1 statement-nn default statement statement-1 statement-2 true true Entry statement-3 statement-x test condition1 test condition3 test condition-n 11
  • 12. Example main() { int units, custnum; float charges; printf("Enter customer no. and units consumedn"); scanf("%d%d",&custnum,&units); if(units<=200) charges=0.5*units; else if(units<=400) charges=100+0.65*(units-200); else if(units<=600) charges=230+0.8*(units-400); else charges=390+(units-600); printf("nnCustomer no:%d Charge=%.2fn", custnum, charges ); }