C++ Pirmer Plus P50 程序清单3.10
对于数值进行加减乘除的运算
/*
C++ Pirmer Plus P50 程序清单3.10
对于数值进行加减乘除的运算
*/
//头文件
#include<iostream>
//主函数
int main(void)
{
using namespace std; //编译指令
float hats, heads;
cout.setf(ios_base::fixed, ios_base::floatfield); //强制规定结果为定点表示
cout << "Enter a number: "; //显示
cin >> hats; //输入第一个值
cout << "Enter another number: "; //显示
cin >> heads; //输入第二个值
cout << "hats = " << hats << "; heads = " << heads << endl; //显示输入数的值对应的数值
cout << "hats + heads = " << hats + heads << endl; //加
cout << "hats - heads = " << hats - heads << endl; //减
cout << "hats * heads = " << hats * heads << endl; //乘
cout << "hats / heads = " << hats / heads << endl; //除
return 0;
}
//浮点类型存储的都是不断靠近的近似值,如果向精确则应采用更高精度的浮点型
总结:浮点类型存储的都是不断靠近的近似值,如果向精确则应采用更高精度的浮点型
感谢观看
再次感谢~