正在加载图片...
C+程计设置浮点教精度 precisioniasetprecision inc lude iostream> *include iomanip> # include〈 cmath> using namespace std int main0//设置小数点后面的位数 i double root= sart(3.0) cout<" set by precision:n"< fixed;/使用 fixed精度 for (int i=0: i<=4: i++) 输出结果: I cout. precision (i): cout << rod Set by precision. return 0: 73 1.732 1.7321C++语言程序设计 9 设置浮点数精度—— precision和setprecision #include <iostream> #include <iomanip> #include <cmath> using namespace std; int main()//设置小数点后面的位数 { double root = sqrt( 3.0 ); cout << " set by precision:\n" << fixed; //使用fixed精度 for (int i = 0; i <= 4; i++ ) { cout.precision( i ); cout << root << endl; } return 0; } 输出结果: Set by precision: 2 1.7 1.73 1.732 1.7321
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有