Annotation of 43BSD/usr.lib/learn/C/L3.1a, revision 1.1

1.1     ! root        1: #print
        !             2: (Section 1.3)
        !             3: The file Ref.c contains a copy of
        !             4: a program to convert Fahrenheit to
        !             5: Celsius that prints from 0 to 300
        !             6: degrees in steps of 20.
        !             7: Modify it to print from 300 down to 0
        !             8: in steps of 50. Type ready when you're done.
        !             9: #once #create Ref
        !            10:  300  148.9
        !            11:  250  121.1
        !            12:  200   93.3
        !            13:  150   65.6
        !            14:  100   37.8
        !            15:   50   10.0
        !            16:    0  -17.8
        !            17: #once #create Ref.c
        !            18: /* print Fahrenheit-Celsius table 
        !            19:        for f = 0, 20, ..., 300 */
        !            20: main()
        !            21: {
        !            22:        int lower, upper, step;
        !            23:        float fahr, celsius;
        !            24: 
        !            25:        lower = 0;      /* lower limit of temperature table */
        !            26:        upper = 300;    /* upper limit */
        !            27:        step = 20;      /* step size */
        !            28: 
        !            29:        fahr = lower;
        !            30:        while (fahr <= upper) {
        !            31:                celsius = (5.0/9.0) * (fahr-32.0);
        !            32:                printf("%4.0f %6.1f\n", fahr, celsius);
        !            33:                fahr = fahr + step;
        !            34:        }
        !            35: }
        !            36: #user
        !            37: a.out >x
        !            38: #cmp Ref x
        !            39: #succeed
        !            40: Here's our solution:
        !            41: 
        !            42: main() /* Fahrenheit-Celsius 300 ... 0 by 50 */
        !            43: {
        !            44:        int lower, upper, step;
        !            45:        float fahr;
        !            46: 
        !            47:        lower = 0;      /* lower limit of temperature table */
        !            48:        upper = 300;    /* upper limit */
        !            49:        step = 50;      /* step size */
        !            50: 
        !            51:        for (fahr = upper; fahr >= lower; fahr = fahr - step)
        !            52:                printf("%4.0f %6.1f\n", fahr, (5.0/9.0) * (fahr-32.0));
        !            53: }
        !            54: #log
        !            55: #next
        !            56: 3.1b 10

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.