-
Notifications
You must be signed in to change notification settings - Fork 1
/
15.c
42 lines (35 loc) · 875 Bytes
/
15.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
#include <stdio.h>
/**
* Converts Fahrenheit to Celsius.
*/
float fahr_to_celsius(float);
/**
* Print Fahrenheit-Celsius Table with header.
*/
main()
{
float fahr, celsius;
float lower, upper, step;
/* lower limit of temperatuire scale */
lower = 0;
/* upper limit */
upper = 300;
/* step size */
step = 20;
fahr = lower;
/* Print table header */
printf("|------------------------------|\n");
printf("| Fahrenheit | Celsius |\n");
printf("|------------------------------|\n");
while (fahr <= upper) {
celsius = fahr_to_celsius(fahr);
printf("| %3.0f | %6.1f |\n", fahr, celsius);
fahr = fahr + step;
}
/* Print table footer */
printf("|------------------------------|\n");
}
float fahr_to_celsius(float fahr)
{
return (5.0/9.0) * (fahr-32.0);
}