Write an
appropriate control structure that will examine the value of a floating point
variable called temp and print one of the following massages, depending on the
value assigned to temp.
(a)
ICE,
if the value of temp is less than 0,
(b)
WATER,
if the value of temp is less than 0,
(c)
STREAM,
if the value of temp is less than 0,
Can a Switch
statement be used in this instead?
Solution:
A
Switch cannot be used because:
- The test involves floating-point quantities rather than integer quantities.
- The test involves ranges of values rather than exact values.
#include<stdio.h>
int main()
{
float temp;
printf("Enter a Temparature: ");
scanf("%f",&temp);
if(temp<0)
printf("ICE");
else if(temp>=0 && temp<=100)
printf("WATER");
else if(temp>100)
printf("STREAM");
}
it is very nisc temp structure .
ReplyDelete