Why result output is integer even result is defined as float?

后端 未结 4 1404
清酒与你
清酒与你 2021-01-23 01:03
#include

using namespace std;

int main(int argc, char** argv){
        float result;
        result=(340/101);
        cout<<\"Result=\"<

        
4条回答
  •  执笔经年
    2021-01-23 02:07

    It's due to integer division, as both operands in the division operation are integers. Either cast one of the numbers to a float, or utilize floating point syntax:

    result = (340.0 / 101.0)
    

提交回复
热议问题