C ++中的算术运算

时间:2016-07-24 14:20:12

标签: c++

#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,请有人帮我理解这一点。

1 个答案:

答案 0 :(得分:2)

您正在进行整数运算。所有操作数都是整数,所有操作都将使用整数运算完成。对于整数除法2/5等于零。

全部使用浮点值:

double arithmetic_operation = (4.+5.)+9.*2.-4.+2./5.+1.-13.;