小编Ste*_*043的帖子

"while()"功能?

该程序应该将华氏度转换为摄氏度:

#include <stdio.h>
int main() {
    float fahrenheit, celsius;
    int max, min, step;

    max = 100;
    min = 0;
    step = 5;

    fahrenheit = 0.0;
    //celsius = (fahrenheit - 32.0) * 5.0/9.0; DOESN'T WORK HERE

    printf("\n");
    printf("This program converts fahrenheit into celsius \n");

    while(fahrenheit <= max) {
        celsius = (fahrenheit - 32.0) * 5.0/9.0; /* Works here */
        printf("%3.0f %6.2f\n", fahrenheit, celsius);
        fahrenheit = fahrenheit + step;
    }
}
Run Code Online (Sandbox Code Playgroud)

正如我在源代码中所提到的那样,当我尝试将摄氏公式放入main()函数体中时,我会得到-17.8每一个华氏值.输出看起来像这样 -

0 -17.78
5 -17.78
10 …
Run Code Online (Sandbox Code Playgroud)

c while-loop

6
推荐指数
1
解决办法
411
查看次数

标签 统计

c ×1

while-loop ×1