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:
1. The test involves floating-point quantities rather than integer quantities.
2. 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");
}
thistimebd Bangladesh Live online newsportal, education, Lifestyle, Health, Photography, gif image etc.
Make your own name or company name website | contact: thistimebd24@gmail.com
Copyright © 2020-2024 News Portal in Bangladesh - THISTIMEBD.COM. ALL Rights Reserved.