SlideShare a Scribd company logo
1 of 14
Presentation Topic: If-else
C if else
Introduction:-
The if statement is used to conditionally execute a statement or a
block of statements. Conditions can be true or false, execute one
thing when the condition is true, something else when the
condition is false.
C if else
Syntax:-
if (expression)
statement(s);
[else statement(s);]
C if else
Example :-
if (a == b)
printf ("%d is equal to %d", a, b);
else
printf ("%d is not equal to %d", a, b);
C if else
If-then statements :-
Syntax:-
if
(expression)
statement(s);
C if else
Note : There is no indentation rule in writing C programming, we can write the above
code in following ways :
If-then statements :-
Example:-
if (a == b)
printf ("%d is equal to %d", a, b);
else
printf ("%d is not equal to %d", a, b);
C if else
If-then statements :-
Example:-
if (a == b)
printf ("if a is equal to b");
printf ("%d is equal to %d", a, b);
if (a == b)
{
printf ("if a is equal to b"); printf
("%d is equal to %d", a,
b);
}
Note : The second way of writing code is a good practice.
C if else
#include<stdio.h>
main()
{
int num;
printf("Input a number : "); scanf("%d",&num); if(num>0)
{
printf("This is a positive integern");
}
else // else portion of if statement
{
printf(" This is not a positive integer..Try againn")
;
}
}
A complete example on conditional if-else statement:-
Example :-
C if else
►#include<stdio.h>
►main()
►{
►int num;
►printf("Input a number : "); scanf("%d",&num); if(num>0)
►{
►printf("This is a positive integern");
►}
►else // else portion of if statement
►{
►printf(" This is not a positive integer..Try againn")
►;
►}
►}
A complete example on conditional if-else statement:-
Example :-
C if else
Sequential if-then statements:-
Example :-
if (a == b)
printf ("a = b");
if (a == c)
printf ("a = c");
if (b == c)
printf ("b = c")
C if else
Multiway if-else-Statement :-
syntax :-
if (expression_1)
statement_1
else if (expression_2)
statement_2
.
.
.
else if (expression_n)
statement_n
else
other_statement
#include<stdio.h> main()
{
int num;
printf("Input score :"); scanf("%d",&num);
if (num>=90)
{
printf("Grade : Excellent");
}
else if(num>=80 && num<90)
{
printf("Grade : Very Good");
}
else if(num>=60 && num<80)
{
printf("Grade : Good");
}
else if(num>=50 && num<60)
{
printf("Grade : Average");
}
else if(num>=40 && num<50)
{
printf("Grade : Poor");
}
else
{
Multiway if-else-Statement :-
Example :-
C if else
C if else
Example
:-
#include<stdio.h>
main()
{
int num1=5, num2=3, num3=-12, min;
if(num1<num2)
{
if(num1<num3)
min = num1; else
min = num3;
}
else
{
if(num2<num3)
min = num2;
else
min = num3;
}
printf("Among %d, %d, %d minimum number is %d",num1
,num2,num3,min);
}
Nested if-then-else statements :-
If else

More Related Content

What's hot

Chapter 4 : Balagurusamy Programming ANSI in C
Chapter 4 : Balagurusamy Programming ANSI in CChapter 4 : Balagurusamy Programming ANSI in C
Chapter 4 : Balagurusamy Programming ANSI in CBUBT
 
C decision making and looping.
C decision making and looping.C decision making and looping.
C decision making and looping.Haard Shah
 
Chapter 3 : Balagurusamy Programming ANSI in C
Chapter 3 : Balagurusamy Programming ANSI in C Chapter 3 : Balagurusamy Programming ANSI in C
Chapter 3 : Balagurusamy Programming ANSI in C BUBT
 
C Language (All Concept)
C Language (All Concept)C Language (All Concept)
C Language (All Concept)sachindane
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programmingAkshay Ithape
 
Control structures in C++ Programming Language
Control structures in C++ Programming LanguageControl structures in C++ Programming Language
Control structures in C++ Programming LanguageAhmad Idrees
 
Fun with Lambdas: C++14 Style (part 1)
Fun with Lambdas: C++14 Style (part 1)Fun with Lambdas: C++14 Style (part 1)
Fun with Lambdas: C++14 Style (part 1)Sumant Tambe
 
RECURSION IN C
RECURSION IN C RECURSION IN C
RECURSION IN C v_jk
 
C presentation book
C presentation bookC presentation book
C presentation bookkrunal1210
 
Trends and future of C++: Evolving a systems language for performance - by Bj...
Trends and future of C++: Evolving a systems language for performance - by Bj...Trends and future of C++: Evolving a systems language for performance - by Bj...
Trends and future of C++: Evolving a systems language for performance - by Bj...devstonez
 
Conditional Statement in C Language
Conditional Statement in C LanguageConditional Statement in C Language
Conditional Statement in C LanguageShaina Arora
 

What's hot (20)

Ansi c
Ansi cAnsi c
Ansi c
 
Chapter 4 : Balagurusamy Programming ANSI in C
Chapter 4 : Balagurusamy Programming ANSI in CChapter 4 : Balagurusamy Programming ANSI in C
Chapter 4 : Balagurusamy Programming ANSI in C
 
Arrays and Strings
Arrays and Strings Arrays and Strings
Arrays and Strings
 
Operators
OperatorsOperators
Operators
 
Python programming : Control statements
Python programming : Control statementsPython programming : Control statements
Python programming : Control statements
 
C pointer basics
C pointer basicsC pointer basics
C pointer basics
 
C decision making and looping.
C decision making and looping.C decision making and looping.
C decision making and looping.
 
Chapter 3 : Balagurusamy Programming ANSI in C
Chapter 3 : Balagurusamy Programming ANSI in C Chapter 3 : Balagurusamy Programming ANSI in C
Chapter 3 : Balagurusamy Programming ANSI in C
 
C Language (All Concept)
C Language (All Concept)C Language (All Concept)
C Language (All Concept)
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programming
 
Control structures in C++ Programming Language
Control structures in C++ Programming LanguageControl structures in C++ Programming Language
Control structures in C++ Programming Language
 
Functions in C
Functions in CFunctions in C
Functions in C
 
Fun with Lambdas: C++14 Style (part 1)
Fun with Lambdas: C++14 Style (part 1)Fun with Lambdas: C++14 Style (part 1)
Fun with Lambdas: C++14 Style (part 1)
 
CProgrammingTutorial
CProgrammingTutorialCProgrammingTutorial
CProgrammingTutorial
 
RECURSION IN C
RECURSION IN C RECURSION IN C
RECURSION IN C
 
C if else
C if elseC if else
C if else
 
Strings
StringsStrings
Strings
 
C presentation book
C presentation bookC presentation book
C presentation book
 
Trends and future of C++: Evolving a systems language for performance - by Bj...
Trends and future of C++: Evolving a systems language for performance - by Bj...Trends and future of C++: Evolving a systems language for performance - by Bj...
Trends and future of C++: Evolving a systems language for performance - by Bj...
 
Conditional Statement in C Language
Conditional Statement in C LanguageConditional Statement in C Language
Conditional Statement in C Language
 

Similar to If else

control stucture in c language
control stucture in c language control stucture in c language
control stucture in c language abdulahi45
 
Decisions in C or If condition
Decisions in C or If conditionDecisions in C or If condition
Decisions in C or If conditionyarkhosh
 
CONTROLSTRUCTURES.ppt
CONTROLSTRUCTURES.pptCONTROLSTRUCTURES.ppt
CONTROLSTRUCTURES.pptSanjjaayyy
 
Conditional statements
Conditional statementsConditional statements
Conditional statementsNabishaAK
 
Programming Fundamentals Decisions
Programming Fundamentals  Decisions Programming Fundamentals  Decisions
Programming Fundamentals Decisions imtiazalijoono
 
LET US C (5th EDITION) CHAPTER 2 ANSWERS
LET US C (5th EDITION) CHAPTER 2 ANSWERSLET US C (5th EDITION) CHAPTER 2 ANSWERS
LET US C (5th EDITION) CHAPTER 2 ANSWERSKavyaSharma65
 
Loop's definition and practical code in C programming
Loop's definition and  practical code in C programming Loop's definition and  practical code in C programming
Loop's definition and practical code in C programming DharmaKumariBhandari
 
6 c control statements branching &amp; jumping
6 c control statements branching &amp; jumping6 c control statements branching &amp; jumping
6 c control statements branching &amp; jumpingMomenMostafa
 
Dti2143 chap 4 control statement part 2
Dti2143 chap 4 control statement part 2Dti2143 chap 4 control statement part 2
Dti2143 chap 4 control statement part 2alish sha
 
LET US C (5th EDITION) CHAPTER 4 ANSWERS
LET US C (5th EDITION) CHAPTER 4 ANSWERSLET US C (5th EDITION) CHAPTER 4 ANSWERS
LET US C (5th EDITION) CHAPTER 4 ANSWERSKavyaSharma65
 
Decision making and branching
Decision making and branchingDecision making and branching
Decision making and branchingSaranya saran
 
Programming for Problem Solving
Programming for Problem SolvingProgramming for Problem Solving
Programming for Problem SolvingSreedhar Chowdam
 

Similar to If else (20)

control stucture in c language
control stucture in c language control stucture in c language
control stucture in c language
 
control statement
control statement control statement
control statement
 
Decisions in C or If condition
Decisions in C or If conditionDecisions in C or If condition
Decisions in C or If condition
 
CONTROLSTRUCTURES.ppt
CONTROLSTRUCTURES.pptCONTROLSTRUCTURES.ppt
CONTROLSTRUCTURES.ppt
 
Conditional statements
Conditional statementsConditional statements
Conditional statements
 
175035 cse lab-03
175035 cse lab-03175035 cse lab-03
175035 cse lab-03
 
C programming
C programmingC programming
C programming
 
Programming Fundamentals Decisions
Programming Fundamentals  Decisions Programming Fundamentals  Decisions
Programming Fundamentals Decisions
 
LET US C (5th EDITION) CHAPTER 2 ANSWERS
LET US C (5th EDITION) CHAPTER 2 ANSWERSLET US C (5th EDITION) CHAPTER 2 ANSWERS
LET US C (5th EDITION) CHAPTER 2 ANSWERS
 
Loop's definition and practical code in C programming
Loop's definition and  practical code in C programming Loop's definition and  practical code in C programming
Loop's definition and practical code in C programming
 
Najmul
Najmul  Najmul
Najmul
 
C faq pdf
C faq pdfC faq pdf
C faq pdf
 
C programming
C programmingC programming
C programming
 
6 c control statements branching &amp; jumping
6 c control statements branching &amp; jumping6 c control statements branching &amp; jumping
6 c control statements branching &amp; jumping
 
Dti2143 chap 4 control statement part 2
Dti2143 chap 4 control statement part 2Dti2143 chap 4 control statement part 2
Dti2143 chap 4 control statement part 2
 
LET US C (5th EDITION) CHAPTER 4 ANSWERS
LET US C (5th EDITION) CHAPTER 4 ANSWERSLET US C (5th EDITION) CHAPTER 4 ANSWERS
LET US C (5th EDITION) CHAPTER 4 ANSWERS
 
Decision making and branching
Decision making and branchingDecision making and branching
Decision making and branching
 
C tutoria input outputl
C tutoria input outputlC tutoria input outputl
C tutoria input outputl
 
Lecture 9- Control Structures 1
Lecture 9- Control Structures 1Lecture 9- Control Structures 1
Lecture 9- Control Structures 1
 
Programming for Problem Solving
Programming for Problem SolvingProgramming for Problem Solving
Programming for Problem Solving
 

Recently uploaded

microprocessor 8085 and its interfacing
microprocessor 8085  and its interfacingmicroprocessor 8085  and its interfacing
microprocessor 8085 and its interfacingjaychoudhary37
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfAsst.prof M.Gokilavani
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineeringmalavadedarshan25
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learningmisbanausheenparvam
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130Suhani Kapoor
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort servicejennyeacort
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoão Esperancinha
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escortsranjana rawat
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escortsranjana rawat
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girlsssuser7cb4ff
 
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝soniya singh
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxpurnimasatapathy1234
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ
 
Current Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLCurrent Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLDeelipZope
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfAsst.prof M.Gokilavani
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidNikhilNagaraju
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130Suhani Kapoor
 

Recently uploaded (20)

microprocessor 8085 and its interfacing
microprocessor 8085  and its interfacingmicroprocessor 8085  and its interfacing
microprocessor 8085 and its interfacing
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineering
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learning
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
 
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Serviceyoung call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girls
 
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptx
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
 
Current Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLCurrent Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCL
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfid
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
 

If else

  • 2. C if else Introduction:- The if statement is used to conditionally execute a statement or a block of statements. Conditions can be true or false, execute one thing when the condition is true, something else when the condition is false.
  • 3. C if else Syntax:- if (expression) statement(s); [else statement(s);]
  • 4. C if else Example :- if (a == b) printf ("%d is equal to %d", a, b); else printf ("%d is not equal to %d", a, b);
  • 5. C if else If-then statements :- Syntax:- if (expression) statement(s);
  • 6. C if else Note : There is no indentation rule in writing C programming, we can write the above code in following ways : If-then statements :- Example:- if (a == b) printf ("%d is equal to %d", a, b); else printf ("%d is not equal to %d", a, b);
  • 7. C if else If-then statements :- Example:- if (a == b) printf ("if a is equal to b"); printf ("%d is equal to %d", a, b); if (a == b) { printf ("if a is equal to b"); printf ("%d is equal to %d", a, b); } Note : The second way of writing code is a good practice.
  • 8. C if else #include<stdio.h> main() { int num; printf("Input a number : "); scanf("%d",&num); if(num>0) { printf("This is a positive integern"); } else // else portion of if statement { printf(" This is not a positive integer..Try againn") ; } } A complete example on conditional if-else statement:- Example :-
  • 9. C if else ►#include<stdio.h> ►main() ►{ ►int num; ►printf("Input a number : "); scanf("%d",&num); if(num>0) ►{ ►printf("This is a positive integern"); ►} ►else // else portion of if statement ►{ ►printf(" This is not a positive integer..Try againn") ►; ►} ►} A complete example on conditional if-else statement:- Example :-
  • 10. C if else Sequential if-then statements:- Example :- if (a == b) printf ("a = b"); if (a == c) printf ("a = c"); if (b == c) printf ("b = c")
  • 11. C if else Multiway if-else-Statement :- syntax :- if (expression_1) statement_1 else if (expression_2) statement_2 . . . else if (expression_n) statement_n else other_statement
  • 12. #include<stdio.h> main() { int num; printf("Input score :"); scanf("%d",&num); if (num>=90) { printf("Grade : Excellent"); } else if(num>=80 && num<90) { printf("Grade : Very Good"); } else if(num>=60 && num<80) { printf("Grade : Good"); } else if(num>=50 && num<60) { printf("Grade : Average"); } else if(num>=40 && num<50) { printf("Grade : Poor"); } else { Multiway if-else-Statement :- Example :- C if else
  • 13. C if else Example :- #include<stdio.h> main() { int num1=5, num2=3, num3=-12, min; if(num1<num2) { if(num1<num3) min = num1; else min = num3; } else { if(num2<num3) min = num2; else min = num3; } printf("Among %d, %d, %d minimum number is %d",num1 ,num2,num3,min); } Nested if-then-else statements :-