#include"iostream"
using namespace std;
int main(){
float arithmetic_operation = (4+5)+9*2-4+2/5+1-13;
cout<< arithmetic_operation << " <--The Result." << endl;
return 0;
}
我得到11&lt; - 结果。但实际上结果是11.4,请有人帮我理解这一点。
答案 0 :(得分:2)
您正在进行整数运算。所有操作数都是整数,所有操作都将使用整数运算完成。对于整数除法2/5
等于零。
全部使用浮点值:
double arithmetic_operation = (4.+5.)+9.*2.-4.+2./5.+1.-13.;