Wednesday, January 20, 2016

Section 1.3 The for statement

Section 1.3 The for statement


Question

There are plenty of different ways to write a program for a particular task. Let’s try a variation on the temperature converter using for loop.

Program

#include <stdio.h>
/* print Fahrenheit-Celsius table */
main()
{
    int fahr;
    for (fahr = 0; fahr <= 300; fahr = fahr + 20)
        printf("%3d %6.1f\n", fahr, (5.0/9.0)*(fahr-32));
}

No comments:

Post a Comment