SlideShare una empresa de Scribd logo
1 de 12
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
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);



Note : There is no indentation rule in writing C programming, we can write the above
code in following ways :
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
A complete example on conditional if-else statement:-
Example :-
               #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")
             ;
              }
             }
C if else
A complete example on conditional if-else statement:-
Example :-
               #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")
             ;
              }
             }
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
C if else
Multiway if-else-Statement :-    #include<stdio.h>
                                main()
Example :-                      {
                                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
                                 {
                                  printf("Grade : Not Promoted");
                                 }
                                }
C if else
Nested if-then-else statements :-
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);
            }

Más contenido relacionado

La actualidad más candente

La actualidad más candente (20)

Operators in c programming
Operators in c programmingOperators in c programming
Operators in c programming
 
C Programming: Control Structure
C Programming: Control StructureC Programming: Control Structure
C Programming: Control Structure
 
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
 
Conditional and control statement
Conditional and control statementConditional and control statement
Conditional and control statement
 
Functions in C
Functions in CFunctions in C
Functions in C
 
Modular programming
Modular programmingModular programming
Modular programming
 
Type Conversion, Precedence and Associativity
Type Conversion, Precedence and AssociativityType Conversion, Precedence and Associativity
Type Conversion, Precedence and Associativity
 
Unit 3. Input and Output
Unit 3. Input and OutputUnit 3. Input and Output
Unit 3. Input and Output
 
Conditional statement c++
Conditional statement c++Conditional statement c++
Conditional statement c++
 
Operators in C Programming
Operators in C ProgrammingOperators in C Programming
Operators in C Programming
 
Looping statements in C
Looping statements in CLooping statements in C
Looping statements in C
 
Loops in c++ programming language
Loops in c++ programming language Loops in c++ programming language
Loops in c++ programming language
 
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
 
Branching in C
Branching in CBranching in C
Branching in C
 
Array in c
Array in cArray in c
Array in c
 
C tokens
C tokensC tokens
C tokens
 
While , For , Do-While Loop
While , For , Do-While LoopWhile , For , Do-While Loop
While , For , Do-While Loop
 
Dynamic memory allocation in c
Dynamic memory allocation in cDynamic memory allocation in c
Dynamic memory allocation in c
 
Functions in c
Functions in cFunctions in c
Functions in c
 
Programming in C Presentation upto FILE
Programming in C Presentation upto FILEProgramming in C Presentation upto FILE
Programming in C Presentation upto FILE
 

Destacado

Conditional statement
Conditional statementConditional statement
Conditional statementMaxie Santos
 
Conditional Statements | If-then Statements
Conditional Statements | If-then StatementsConditional Statements | If-then Statements
Conditional Statements | If-then Statementssheisirenebkm
 
Loops in C Programming
Loops in C ProgrammingLoops in C Programming
Loops in C ProgrammingHimanshu Negi
 
Conditional Statements
Conditional StatementsConditional Statements
Conditional Statementsmicdsram
 
1.3.2 Conditional Statements
1.3.2 Conditional Statements1.3.2 Conditional Statements
1.3.2 Conditional Statementssmiller5
 
Programming Basics if then else, switch, operators
Programming Basics if then else, switch, operatorsProgramming Basics if then else, switch, operators
Programming Basics if then else, switch, operatorsTrivuz ত্রিভুজ
 
Conditional Statements
Conditional StatementsConditional Statements
Conditional Statementselissamiller
 
Mesics lecture 6 control statement = if -else if__else
Mesics lecture 6   control statement = if -else if__elseMesics lecture 6   control statement = if -else if__else
Mesics lecture 6 control statement = if -else if__elseeShikshak
 
Array Presentation (EngineerBaBu.com)
Array Presentation (EngineerBaBu.com)Array Presentation (EngineerBaBu.com)
Array Presentation (EngineerBaBu.com)EngineerBabu
 
Array in c language
Array in c languageArray in c language
Array in c languagehome
 
C++ Programming Club-Lecture 2
C++ Programming Club-Lecture 2C++ Programming Club-Lecture 2
C++ Programming Club-Lecture 2Ammara Javed
 

Destacado (20)

Conditional statement
Conditional statementConditional statement
Conditional statement
 
Conditional Statements | If-then Statements
Conditional Statements | If-then StatementsConditional Statements | If-then Statements
Conditional Statements | If-then Statements
 
Loops in C Programming
Loops in C ProgrammingLoops in C Programming
Loops in C Programming
 
Conditional Statements
Conditional StatementsConditional Statements
Conditional Statements
 
1.3.2 Conditional Statements
1.3.2 Conditional Statements1.3.2 Conditional Statements
1.3.2 Conditional Statements
 
Conditional statements
Conditional statementsConditional statements
Conditional statements
 
Loops in c
Loops in cLoops in c
Loops in c
 
C++ loop
C++ loop C++ loop
C++ loop
 
Estrutura de controle if else
Estrutura de controle if elseEstrutura de controle if else
Estrutura de controle if else
 
Programming Basics if then else, switch, operators
Programming Basics if then else, switch, operatorsProgramming Basics if then else, switch, operators
Programming Basics if then else, switch, operators
 
Conditional Statements
Conditional StatementsConditional Statements
Conditional Statements
 
Switch case and looping
Switch case and loopingSwitch case and looping
Switch case and looping
 
Mesics lecture 6 control statement = if -else if__else
Mesics lecture 6   control statement = if -else if__elseMesics lecture 6   control statement = if -else if__else
Mesics lecture 6 control statement = if -else if__else
 
Loops c++
Loops c++Loops c++
Loops c++
 
Loops in C
Loops in CLoops in C
Loops in C
 
Array Presentation (EngineerBaBu.com)
Array Presentation (EngineerBaBu.com)Array Presentation (EngineerBaBu.com)
Array Presentation (EngineerBaBu.com)
 
Array in c language
Array in c languageArray in c language
Array in c language
 
Control statements
Control statementsControl statements
Control statements
 
C++ Programming Club-Lecture 2
C++ Programming Club-Lecture 2C++ Programming Club-Lecture 2
C++ Programming Club-Lecture 2
 
Unit 3
Unit 3Unit 3
Unit 3
 

Similar a C if else

control stucture in c language
control stucture in c language control stucture in c language
control stucture in c language abdulahi45
 
All important c programby makhan kumbhkar
All important c programby makhan kumbhkarAll important c programby makhan kumbhkar
All important c programby makhan kumbhkarsandeep kumbhkar
 
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
 
Decision making and branching
Decision making and branchingDecision making and branching
Decision making and branchingSaranya saran
 
Conditional statements
Conditional statementsConditional statements
Conditional statementsNabishaAK
 
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
 
Programming Fundamentals Decisions
Programming Fundamentals  Decisions Programming Fundamentals  Decisions
Programming Fundamentals Decisions imtiazalijoono
 
Computer programming subject notes. Quick easy notes for C Programming.Cheat ...
Computer programming subject notes. Quick easy notes for C Programming.Cheat ...Computer programming subject notes. Quick easy notes for C Programming.Cheat ...
Computer programming subject notes. Quick easy notes for C Programming.Cheat ...DR B.Surendiran .
 
5 c control statements looping
5  c control statements looping5  c control statements looping
5 c control statements loopingMomenMostafa
 

Similar a C if else (20)

If else
If elseIf else
If else
 
control stucture in c language
control stucture in c language control stucture in c language
control stucture in c language
 
L3 control
L3 controlL3 control
L3 control
 
C faq pdf
C faq pdfC faq pdf
C faq pdf
 
06 1 조건문
06 1 조건문06 1 조건문
06 1 조건문
 
All important c programby makhan kumbhkar
All important c programby makhan kumbhkarAll important c programby makhan kumbhkar
All important c programby makhan kumbhkar
 
C programming
C programmingC programming
C programming
 
C lab manaual
C lab manaualC lab manaual
C lab manaual
 
Cprogramcontrolifelseselection3
Cprogramcontrolifelseselection3Cprogramcontrolifelseselection3
Cprogramcontrolifelseselection3
 
C programming
C programmingC programming
C programming
 
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
 
Decision making and branching
Decision making and branchingDecision making and branching
Decision making and branching
 
Conditional statements
Conditional statementsConditional statements
Conditional statements
 
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
 
C programms
C programmsC programms
C programms
 
Programming Fundamentals Decisions
Programming Fundamentals  Decisions Programming Fundamentals  Decisions
Programming Fundamentals Decisions
 
Computer programming subject notes. Quick easy notes for C Programming.Cheat ...
Computer programming subject notes. Quick easy notes for C Programming.Cheat ...Computer programming subject notes. Quick easy notes for C Programming.Cheat ...
Computer programming subject notes. Quick easy notes for C Programming.Cheat ...
 
5 c control statements looping
5  c control statements looping5  c control statements looping
5 c control statements looping
 
Control statement
Control statementControl statement
Control statement
 

Más de Ritwik Das

Más de Ritwik Das (6)

SQL JOIN
SQL JOINSQL JOIN
SQL JOIN
 
SQL UNION
SQL UNIONSQL UNION
SQL UNION
 
Concat presentation
Concat presentationConcat presentation
Concat presentation
 
Mysql count
Mysql countMysql count
Mysql count
 
Learning java
Learning javaLearning java
Learning java
 
Php variables
Php variablesPhp variables
Php variables
 

Último

Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...apidays
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024The Digital Insurer
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024The Digital Insurer
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Orbitshub
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamUiPathCommunity
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Zilliz
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfOverkill Security
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Angeliki Cooney
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 

Último (20)

Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 

C if else

  • 1. 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.
  • 2. C if else Syntax:- if (expression) statement(s); [else statement(s);]
  • 3. 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);
  • 4. C if else If-then statements :- Syntax:- if (expression) statement(s);
  • 5. C if else 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); Note : There is no indentation rule in writing C programming, we can write the above code in following ways :
  • 6. 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.
  • 7. C if else A complete example on conditional if-else statement:- Example :- #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") ; } }
  • 8. C if else A complete example on conditional if-else statement:- Example :- #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") ; } }
  • 9. 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")
  • 10. 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
  • 11. C if else Multiway if-else-Statement :- #include<stdio.h> main() Example :- { 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 { printf("Grade : Not Promoted"); } }
  • 12. C if else Nested if-then-else statements :- 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); }