一个将华氏度转化为摄氏度的程序,但是输出总是零
#include<stdio.h>
int main(){
float F;
double c;
scanf("%f",&F);
c = (double)(5/9)*(F-32);
printf("%lf",c);
}
其实是5/9这里,它因为是整形,所以就默认为零了!
如果不想更换这个c的结构的话,将5和9都强制转化为double
#include<stdio.h>
int main(){
float F;
double c;
scanf("%f",&F);
c = (double)(5)/(double)(9)*(F-32);
printf("%lf",c);
}