-
Notifications
You must be signed in to change notification settings - Fork 0
/
Assignment2ex12.c
44 lines (37 loc) · 1.13 KB
/
Assignment2ex12.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/* Write a C function that calculates the required heater activation time
according to the input temperature of water.
- if input temperature is from 0 to 30,
then required heating time = 7
mins.
- if input temperature is from 30 to 60, then
required heating time = 5
mins.
- if input temperature is from 60 to 90,
then required heating time = 3
mins.
- if input temperature is more than 90, then
required heating time = 1
mins.
- if temperature is invalid (more than 100), return 0
Example:
Input = 10 → output = 7
Input = 35 → output = 5 */
#include<stdio.h>
int heaterActievationTime(int temperature );
int main() {
int temp;
scanf("%d" , &temp);
printf("the requird heating time is %d " , heaterActievationTime(temp));
}
int heaterActievationTime(int temperature ) {
if (temperature > 0 && temperature <= 30 )
return 7 ;
else if (temperature > 30 && temperature <= 60)
return 5 ;
else if (temperature > 60 && temperature <=90)
return 3;
else if (temperature > 90 && temperature <100)
return 1;
else
return 0 ;
}