Question :
Develop a C program to get the temperature and print the following status according to the given temperature by using else if ladder statement.
1. T<=0 "Its very very cold".
2. 0 > T < 10 "Its cold".
3. 10 > T < =20 "Its cool out".
4. 20 > T < =30 "Its warm".
5. T>30 "Its hot".
#include <stdio.h>
#include <stdlib.h>
int main()
{
float temperature;
// get the temperature
printf("Enter temperature: ");
scanf("%f",&temperature);
//1. T<=0 "Its very very cold".
if(temperature<=0){
printf("\nIts very very cold\n");
}else if(temperature>0 && temperature<=10){
//2. 0 > T < 10 "Its cold".
printf("\nIts cold\n");
}else if(temperature>10 && temperature<=20){
//3. 10 > T < =20 "Its cool out".
printf("\nIts cool out\n");
}else if(temperature>20 && temperature<=30){
//4. 20 > T < =30 "Its warm".
printf("\nIts warm\n");
}else if(temperature>30){
//5. T>30 "Its hot".
printf("\nIts hot\n");
}
getchar();
getchar();
return 0;
}
Comments
Leave a comment