当前位置: 动力学知识库 > 问答 > 编程问答 >

program in C launches correctly but printf doesnt show anything

问题描述:

I run the programm and the console appears but printf doesnt print anything,

how can I fix this?

#include<stdio.h>

main()

{

float fa;

int cel;

cel=0;

while(cel<=200);

{

fa=9.000*(cel+32.000)/5.000;

printf("%d\t%.3f\n",cel,fa);

cel=cel+20;

}

}

In addition I have a very similar program that runs correctly

#include<stdio.h>

main()

{

float celsius;

int fahr;

fahr = 0;

while(fahr<=100){

celsius=5.0000*(fahr-32.0000)/9.0000;

printf("%d\t%.4f\n",fahr,celsius);

fahr=fahr+1;

}

}

I ran both programs in c-free 5

网友答案:

Infinite loop:

while(cel<=200);

because of trailing ; it is equivalent to:

while(cel<=200) {}

which means the printf() is never reached and cel is never modified. Remove the ; to correct.

网友答案:

Please remove semicolon after while

while(cel<=200)  

Correct code is :

#include<stdio.h>
main()
{
    float fa;
    int cel;
    cel=0;
    while(cel<=200) // semicolon removed here
    {
        fa=9.000*(cel+32.000)/5.000;
        printf("%d\t%.3f\n",cel,fa);
        cel=cel+20;
    }
}
分享给朋友:
您可能感兴趣的文章:
随机阅读: