-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexercise1-3.c
37 lines (27 loc) · 819 Bytes
/
exercise1-3.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
# include <stdio.h>
// Symbolic Constants
#define LOWER 0
#define UPPER 300
#define STEP 20
int convert_fahrenheit_celsius(int fahrenheit);
int main() {
int celsius;
int fahrenheit = LOWER;
FILE *f;
f = fopen("celsius_to_fahrenheit.txt", "w");
printf("%s\t%s\n", "Fahrenheit", "Celsius");
// fprintf("%s\t%s\n", "Fahrenheit", "Celsius");
while (fahrenheit <= UPPER) {
celsius = convert_fahrenheit_celsius(fahrenheit);
// To Print to Screen
printf("%d\t%d\n", fahrenheit, celsius);
// To Print to File
// fprintf(f, "%d\t%d\n", fahrenheit, celsius);
fahrenheit += STEP;
}
fclose(f);
}
int convert_fahrenheit_celsius(int fahrenheit) {
int celsius = (5 * (fahrenheit - 32)) / 9;
return celsius;
}