Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
oorrja
GitHub Repository: oorrja/learntosolveit
Path: blob/master/languages/cprogs/Ex_1.15_tempconv.c
1240 views
1
/**
2
*
3
* Exercise 1.15
4
*
5
* Temperature Conversion. Floating point, Symbolic Constant. Functions
6
*
7
**/
8
9
10
#include < stdio.h >
11
12
#define LOWER 0
13
#define UPPER 300
14
#define STEP 20
15
16
void fahrtocelsius(void);
17
void celsiustofahr(void);
18
19
int main(void) {
20
int c;
21
22
printf("Temperature Conversion Table\n");
23
printf("1 - Fahrenheit to Celsius Conversion\n");
24
printf("2 - Celsius to Fahrenheit Conversion\n");
25
printf("- Enter your Choice\n");
26
27
c = getchar();
28
29
if (c == '1')
30
fahrtocelsius();
31
else if (c == '2')
32
celsiustofahr();
33
else
34
printf("Invalid Choice\n");
35
36
return 0;
37
}
38
39
void fahrtocelsius() {
40
float fahr;
41
42
for (fahr = LOWER; fahr <= UPPER; fahr = fahr + STEP)
43
printf("%3.0f%6.1f\n", fahr, (5.0 / 9.0) * (fahr - 32.0));
44
}
45
46
void celsiustofahr() {
47
float celsius;
48
49
for (celsius = LOWER; celsius <= UPPER; celsius = celsius + STEP)
50
printf("%3.0f%6.1f\n", celsius, (9.0 * celsius) / 5.0 + 32);
51
}
52
53