educoder实训答案(4)

#C&C++基本输入输出实训
##第4关:不同精度的PI

  • 代码
#include <iostream>

// 包含流操作算子库
#include <iomanip>
using namespace std;

// 定义常量PI,后面可以直接用PI代替后面的数值
#define PI 3.14159265358979323846

int main()
{
    int n;
    // 请在此添加你的代码,输入n,按不同的精度输出PI
    /********** Begin *********/
	cin >> n;
	if(n==0){
		cout << 3 << endl;
	}else{
		cout << setiosflags(ios::showpoint) << setprecision(n+1) << PI << endl;
	}
	cout << setiosflags(ios::showpoint) << setprecision(n+2) << PI << endl;
	cout << setiosflags(ios::showpoint) << setprecision(n+3) << PI << endl;
	cout << setiosflags(ios::showpoint) << setprecision(n+4) << PI << endl;
	cout << setiosflags(ios::showpoint) << setprecision(n+5) << PI;
	

	
    /********** End **********/
	
    return 0;
}

发布了29 篇原创文章 · 获赞 43 · 访问量 23万+

猜你喜欢

转载自blog.csdn.net/xiaoyuge16/article/details/79451004
今日推荐