首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

求教C语言解决办法

2013-01-17 
求教C语言我在visual studio 2010下编译的代码如下:#includestdio.hmain(){double c0, ff0scanf(ent

求教C语言
我在visual studio 2010下编译的代码如下:
#include<stdio.h>
main()
{
double c=0, ff=0;
scanf("enter the temperature:%lf",&ff);
c=(5/9)*(ff-32);
printf("exchange ff to c temperature is %fl",c);
getch();
return(0);
}
编译成功了。
可是不论我输入的变量是多少出来都是一个答案-0.0000001
[解决办法]
scanf的用法和浮点数运算不对,这样改:


#include<stdio.h>
main()
{
double c=0, ff=0;
printf("enter the temperature:");
scanf("%lf",&ff);
c=(5.0/9)*(ff-32);
printf("exchange ff to c temperature is %lf\n",c);
getch();
return(0);
}

[解决办法]

#include<stdio.h>
main()
{
double c=0, ff=0;
printf("enter the temperature:");
scanf("%lf", &ff);
c=(5/9.0)*(ff-32);    //这儿5/9应该改为5.0/9或者5/9.0否则计算的结果是5/9是0
printf("exchange ff to c temperature is %fl",c);
getch();
return(0);
}

热点排行