C语言小白问题 ①代码如图1 运行结果如图2 为什么第三行显示0.0,哪里错了②或者像下文这样写,哪里错(语法错误不算。。)?为什么运行结果(如图3)不一样?
#include <stdio.h>
#define gasolineconversionfactor 3.785
#define distanceconversionfactor 1.609
int main()
{
float miles,gallons;
printf("Please enter the number of miles traveled.\n");
scanf("%f",&miles);
printf("Then please enter the number of gallons of gasoline.\n");
scanf("%f",&gallons);
printf("The number of miles per gallon is:%.1f\n",miles/gallons);
printf("In American way,it will be%.1f\n",gallons*gasolineconversionfactor/miles*distanceconversionfactor*100);
return 0;
}
printf("In American way,it will be%.1f\n",gallons*gasolineconversionfactor/miles*distanceconversionfactor*100);
一个加了括号,一个没有加, 算法是不一样的。去试试你就知道了。
优先级的问题。
在正常数学中加括号不是不影响吗,这里为什么影响?什么道理?
本回答被提问者和网友采纳在printf中
可不就是0.0吗