C++编程练习注意事项

版权声明:扫我头像就可以向我提问,共同提高:) https://blog.csdn.net/u011436427/article/details/86484921

1.float,double单双精度的赋值问题需要注意,看图就明白了,注意a和e的区别

#include<iostream>
int main()
{
	 float a=1/3.0,b=1/1.0,c=1/4.0,d=1/5.0;
    float e=(1/3);
    float res;
    res=1/(a+b+c+d);


    cout<<e<<endl;
    cout<<a<<endl;
    cout<<res<<endl;
}

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/u011436427/article/details/86484921