C - The C Answer (2nd Edition) - Exercise 1-4

来源:互联网 发布:windows安装部署hive 编辑:程序博客网 时间:2024/05/04 00:29
/*Write a program to print the corresponding Celsius to Fahrenheit table.*/#include <stdio.h>/* print Celsius-Fahrenheit table for celsius = 0, 20, ..., 300; floating-point version */main(){    float fahr, celsius;    int lower, upper, step;        lower = 0;   /* lower limit of temperature table */    upper = 300; /* upper limit                      */    step  = 20;  /* step size                        */        printf("Celsius Fahr\n");    celsius = lower;    while (celsius <= upper)    {    fahr = (9.0 * celsius) / 5.0 + 32.0;    printf("%3.0f %6.1f\n", celsius, fahr);    celsius += step;    }}/* Output:Celsius Fahr  0   32.0 20   68.0 40  104.0 60  140.0 80  176.0100  212.0120  248.0140  284.0160  320.0180  356.0200  392.0220  428.0240  464.0260  500.0280  536.0300  572.0Press any key to continue . . .*/
1 0
原创粉丝点击