educoder实训答案(4)

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

  • 代码
#include 

// 包含流操作算子库
#include 
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;
}

你可能感兴趣的:(educoder实训)