summaryrefslogtreecommitdiff
path: root/ctof.c
blob: 7e2cbefbcc78c90d7bdcb7eecb61febfca712a31 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include<stdio.h>

/*
 * Print Celcius-Fahrenheit table for celcius = 0, 20, ... 300.
 */
main() {
    float fahr, celcius;
    int lower, upper, step;

    lower = 0;      // lower limit of temperature table
    upper = 300;    // upper limit of temperature table
    step = 20;      // step size

    celcius = lower;

    printf("%3s %6s\n", "C", "F");

    while (celcius <= upper) {
        fahr = (9.0 / 5.0) * celcius + 32.0;
        printf("%3.0f %6.1f\n", celcius, fahr);
        celcius = celcius + step;
    }
}