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 */
}
Output:
Flowchart:
|
No comments:
Post a Comment
Feel free to ask us any question regarding this post