SlideShare a Scribd company logo
2
Most read
6
Most read
12
Most read
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);
            }

More Related Content

PPTX
If statements in c programming
PPTX
Conditional Statement in C Language
PPT
Python Pandas
PPT
Constants in C Programming
ODP
The Full Stack Web Development
PPT
Introduction to Basic C programming 01
PPTX
Parameter passing to_functions_in_c
PPTX
Nesting of if else statement & Else If Ladder
If statements in c programming
Conditional Statement in C Language
Python Pandas
Constants in C Programming
The Full Stack Web Development
Introduction to Basic C programming 01
Parameter passing to_functions_in_c
Nesting of if else statement & Else If Ladder

What's hot (20)

PPTX
Looping statements in C
PPTX
C Programming: Control Structure
PPTX
Unit 3. Input and Output
PDF
Operators in c programming
PPT
Basics of C programming
PPTX
Functions in c++
PDF
Python exception handling
PPTX
Programming in c Arrays
PPT
PPT
Structure of a C program
PDF
Python programming : Control statements
PPTX
Inline function
PPTX
Operators in Python
PPTX
Recursive Function
PPT
RECURSION IN C
PPTX
If else statement in c++
PDF
10. switch case
PPTX
Data types in python
PPTX
Pointers in c++
Looping statements in C
C Programming: Control Structure
Unit 3. Input and Output
Operators in c programming
Basics of C programming
Functions in c++
Python exception handling
Programming in c Arrays
Structure of a C program
Python programming : Control statements
Inline function
Operators in Python
Recursive Function
RECURSION IN C
If else statement in c++
10. switch case
Data types in python
Pointers in c++
Ad

Viewers also liked (20)

PPTX
CONDITIONAL STATEMENT IN C LANGUAGE
PPSX
Conditional statement
PDF
Conditional Statements | If-then Statements
PPTX
Loops in C Programming
PPT
Conditional Statements
PDF
1.3.2 Conditional Statements
PPTX
Conditional statements
PPTX
C++ loop
PPT
Estrutura de controle if else
PPTX
Programming Basics if then else, switch, operators
PPT
Conditional Statements
PPTX
Switch case and looping
PPT
Mesics lecture 6 control statement = if -else if__else
PPTX
Loops c++
PPTX
Loops in C
PPT
Array Presentation (EngineerBaBu.com)
PPTX
Array in c language
PDF
Control statements
PPTX
C++ Programming Club-Lecture 2
CONDITIONAL STATEMENT IN C LANGUAGE
Conditional statement
Conditional Statements | If-then Statements
Loops in C Programming
Conditional Statements
1.3.2 Conditional Statements
Conditional statements
C++ loop
Estrutura de controle if else
Programming Basics if then else, switch, operators
Conditional Statements
Switch case and looping
Mesics lecture 6 control statement = if -else if__else
Loops c++
Loops in C
Array Presentation (EngineerBaBu.com)
Array in c language
Control statements
C++ Programming Club-Lecture 2
Ad

Similar to C if else (20)

PPTX
RTF
control stucture in c language
PPT
L3 control
PDF
C faq pdf
PDF
PPT
All important c programby makhan kumbhkar
PPTX
DOCX
C lab manaual
PDF
Cprogramcontrolifelseselection3
PDF
POP Unit 2.pptx.pdf for your time and gauss with example
PDF
C programming
PPT
Decisions in C or If condition
PPT
CONTROLSTRUCTURES.ppt
PPTX
Decision making and branching
PPTX
Conditional statements
PDF
LET US C (5th EDITION) CHAPTER 2 ANSWERS
PDF
C programms
PDF
Programming Fundamentals Decisions
PDF
Computer programming subject notes. Quick easy notes for C Programming.Cheat ...
PDF
5 c control statements looping
control stucture in c language
L3 control
C faq pdf
All important c programby makhan kumbhkar
C lab manaual
Cprogramcontrolifelseselection3
POP Unit 2.pptx.pdf for your time and gauss with example
C programming
Decisions in C or If condition
CONTROLSTRUCTURES.ppt
Decision making and branching
Conditional statements
LET US C (5th EDITION) CHAPTER 2 ANSWERS
C programms
Programming Fundamentals Decisions
Computer programming subject notes. Quick easy notes for C Programming.Cheat ...
5 c control statements looping

More from Ritwik Das (6)

PPTX
SQL JOIN
PPTX
SQL UNION
PPTX
Concat presentation
ODP
Mysql count
ODP
Learning java
PPT
Php variables
SQL JOIN
SQL UNION
Concat presentation
Mysql count
Learning java
Php variables

Recently uploaded (20)

PDF
solutions_manual_-_materials___processing_in_manufacturing__demargo_.pdf
PPTX
Comunidade Salesforce São Paulo - Desmistificando o Omnistudio (Vlocity)
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
Transforming Manufacturing operations through Intelligent Integrations
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPTX
Telecom Fraud Prevention Guide | Hyperlink InfoSystem
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Review of recent advances in non-invasive hemoglobin estimation
PPTX
Cloud computing and distributed systems.
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
solutions_manual_-_materials___processing_in_manufacturing__demargo_.pdf
Comunidade Salesforce São Paulo - Desmistificando o Omnistudio (Vlocity)
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Transforming Manufacturing operations through Intelligent Integrations
CIFDAQ's Market Insight: SEC Turns Pro Crypto
MYSQL Presentation for SQL database connectivity
Advanced methodologies resolving dimensionality complications for autism neur...
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Per capita expenditure prediction using model stacking based on satellite ima...
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
Reach Out and Touch Someone: Haptics and Empathic Computing
Diabetes mellitus diagnosis method based random forest with bat algorithm
Telecom Fraud Prevention Guide | Hyperlink InfoSystem
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Chapter 3 Spatial Domain Image Processing.pdf
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Review of recent advances in non-invasive hemoglobin estimation
Cloud computing and distributed systems.
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx

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