Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
oorrja
GitHub Repository: oorrja/learntosolveit
Path: blob/master/languages/cprogs/Ex_1.3_fahr2celheading.c
1240 views
1
/***
2
*
3
* Exercise 1-3. Modify the temperature conversion program,
4
* Fahrenheit to Celsius, to print a heading above the table.
5
*
6
* print Fahrenheit-Celsius table for fahr = 0, 20, ..., 300;
7
* floating-point version.
8
*
9
***/
10
11
#include<stdio.h>
12
13
int main(void)
14
{
15
printf("A program print Fahrenheit-Celsius\n");
16
17
float fahr, celsius;
18
int lower, upper, step;
19
20
lower = 0;
21
upper = 300;
22
step = 20;
23
24
fahr = lower;
25
26
27
printf("Fahr\tCelsius\t \n");
28
29
while(fahr <= upper)
30
{
31
celsius = (5.0/9.0) * (fahr - 32.0);
32
printf("%4.0f %10.1f\n", fahr, celsius);
33
fahr = fahr + step;
34
}
35
36
return 0;
37
}
38
39