查看完整内容
你的程序并没有错,错在不是你想要的结果。 ‘/’的优先级高于‘+’
如果把表达式(float)(a+b)/3+(int)c改为(float)(a+b)/(3+(int)c)如你所愿了,如下程序:
#include
int main()
{
int a,b;
float c;
a=3;
b=2;
c=2.5;
printf("the total is %f\n",(float)(a+b)/(3+(int)c));
sleep(5000);
return 0;
}
这样输出的结果就是你想要的结果1.00000: