gpt4 book ai didi

c - C 程序正确启动但 printf 不显示任何内容

转载 作者:行者123 更新时间:2023-11-30 20:44:10 24 4
gpt4 key购买 nike

我运行程序并出现控制台,但 printf 不打印任何内容,我该如何解决这个问题?

#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;
}
}

此外,我有一个非常相似的程序,可以正确运行

#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;
}
}

我在 c-free 5 中运行了这两个程序

最佳答案

无限循环:

while(cel<=200);

因为尾随;,它相当于:

while(cel<=200) {}

这意味着永远不会到达printf()并且永远不会修改cel。删除 ; 进行更正。

关于c - C 程序正确启动但 printf 不显示任何内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18108447/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com