if else ladder in C example with flowchart and explanation.

if else ladder in C example with flowchart


     we use if else ladder when we have multiple conditions with different different statements to execute. here is a small example were user can enter temperature and according to entered temperature value respective statement will be executed.

Program:

/*C Program to print text according to entered temperature Using If-Else Ladder By Slashmycode.com */
#include<stdio.h>
#include<conio.h>
void main()
{
int temp;
clrscr();

printf("Enter the temperature: ");
scanf("%d",&temp);

if(temp<=0)
  printf("Its Very Very Cold!!!");
    else if(temp>=1 && temp<=10)
             printf("Its Cold");
    else if(temp>=11 && temp<=20)
             printf("Its Cold Out");
    else if(temp>=21 && temp<=30)
             printf("Its Warm");
    else
         printf("Its HOT");

getch();
/*C Program to print text according to entered temperature Using If-Else Ladder By Slashmycode.com */

}

See another example for if else ladder

Output:


if else ladder in C example with flowchart

Flowchart:
if else ladder in C flowchart
Click on image to enlarge





No comments:

Post a Comment

Feel free to ask us any question regarding this post