]> zdv2.bktei.com Git - BK-2023-05.git/blob - src/kr_exercises/ch1/s1.2/c_to_f_float.c
feat(src/kr/s1.5):Add more examples
[BK-2023-05.git] / src / kr_exercises / ch1 / s1.2 / c_to_f_float.c
1 /* Desc: simple temperature converter
2 * Usage: ./s1..c_to_f_float.c
3 * Ref/Attrib: The C Programming Language, 2nd Edition, Section 1.2
4 */
5
6 #include <stdio.h>
7 //#include <stdlib.h>
8
9 /* print Celsius-Fahrenheit table for celsius = -50, -40, ..., 100 */
10
11 int main(){
12 float fahr, celsius;
13 int lower, upper, step;
14
15 lower = -50; /* lower limit of temperature table */
16 upper = 100; /* upper limit */
17 step = 5; /* step size */
18
19 celsius = lower;
20 printf(" °C, °F\n");
21 while (celsius <= upper){
22 fahr = (celsius * (9.0 / 5.0)) + 32.0;
23 printf("%3.0f,%7.2f\n", celsius, fahr);
24 celsius = celsius + step;
25 };
26
27
28 printf("\n\nDone\n\n");
29 return 0;
30 };
31
32
33
34
35 /*
36 * Author: Steven Baltakatei Sandoval
37 * License: GPLv3+
38 */