C++ Primer Plus P51 程序清单3.11(用整、定点、e表示法进行除法运算)——中职

C++ Primer Plus P51 程序清单3.11

用整、定点、e表示法进行除法运算

/*
C++ Primer Plus
用整、定点、e表示法进行除法运算
*/

//头文件
#include<iostream>

//主函数
int main(void)
{
    
    
	using namespace std;														//编译指令
	cout.setf(ios_base::fixed, ios_base::floatfield);							//将浮点类型输出规定为定点表示

	cout << "Integer division: 9 / 5 = " << 9 / 5 << endl;						//计算整型常量相除的值
	cout << "Floating-point division: 9.0 / 5.0 = " << 9.0 / 5.0 << endl;		//计算单精度浮点数相除的值
	cout << "Mixed division: 9.0 / 5 = " << 9.0 / 5 << endl;					//计算单精度浮点数和整型常量相除的值
	cout << "double constants: 1e7 / 9.0 = " << 1e7 / 9.0 << endl;				//计算e表示法的浮点数和双精度浮点数相除的值
	cout << "float constants: 1e7f / 9.0 = " << 1.e7f / 9.0f << endl;			//计算e表示法的浮点数和单精度浮点数相除的值

	return 0;
}

需要注意的是:

	cout << "double constants: 1e7 / 9.0 = " << 1e7 / 9.0 << endl;				//计算e表示法的浮点数和双精度浮点数相除的值
	cout << "float constants: 1e7f / 9.0 = " << 1.e7f / 9.0f << endl;			//计算e表示法的浮点数和单精度浮点数相除的值

计算e表示法的浮点数和双精度浮点数相除的值

cout << "double constants: 1e7 / 9.0 = " << 1e7 / 9.0 << endl;				//计算e表示法的浮点数和双精度浮点数相除的值

计算e表示法的浮点数和单精度浮点数相除的值

cout << "float constants: 1e7f / 9.0 = " << 1.e7f / 9.0f << endl;			//计算e表示法的浮点数和单精度浮点数相除的值

注意分清单精度和双精度的运算表示

感谢观看

再次感谢~

猜你喜欢

转载自blog.csdn.net/qq_51212951/article/details/113426649
今日推荐