帮我看看这个C语言程序哪里错了????为什么 我的不到想要的结果呢??

来源:百度知道 编辑:UC知道 时间:2024/06/17 22:18:15
#include<stdio.h>
void main()
{
float radius=0.0f;
float diameter=6.0f;
float circumference=0.0f;
float area=0.0f;
float pi=3.1415926f;
printf("Input the diameter of the table:");

scanf("%f",&diameter);

radius=diameter/2.0f;
circumference=2.0f*radius*pi;
area=pi*radius*radius;
printf("\nThe circumference is %.2f",circumference);
printf("\nThe area is %.2f\n",area);
}
为什么 到scanf前能翻译出后面就不显示了呢????
在我电脑上 这个程序得到的翻译结果是 Input the diameter of the table:但是我用的教材上不是 后面还有几句呢

运行没错啊,你是用的什么编译器
Input the diameter of the table:在这个之后输入数字啊,然后回车

我运行了没错啊
还有你这句话 到scanf前能翻译出后面就不显示了呢????
谁能看懂?

有些IDE在程序结束之后会自动退回到程序编辑界面,你需要进入相应的界面才能够查看运行结果,比如TC里,你需要进入DOS界面看结果(我记得快捷键好像是ALT+F5)。

在程序之后加句
getch() 记得好象是这个吧
反正就是等待接收一个字符输入
试试

#include<stdio.h>

int main(void)
{
float radius=0;
float diameter=6;
float circumference=0;
float area=0;
float pi=3.1415926;

printf("Input the diameter of the table: ");
scanf("%f",&diameter);

radius=diameter/2;
circumference=2*radius*pi;
area=pi*radius*radius;
printf("\nThe circumference is %.2f",circumference);
printf("\nThe area is %.2f\n",area);

getch();

return 0;
}

LZ在程序的最后加一个getch()试试。。