📄 圆周率的求法.cpp
字号:
//利用级数公式近似求解PI
#include<iostream.h>
#include<iomanip.h>
#include<math.h>
void main()
{
double pi=0;
double x=1;
long k=1;
int sign=1;
while(fabs(x)>1e-8)
//fabs():Calculates the absolute value of the floating-point argument
{
pi=pi+x;
k=k+2;
sign=-sign;
x=sign/double(k);
}
pi=pi*4;
cout<<"The value of PI is :"
<<setiosflags(ios::fixed)
//Insert floating-point values in fixed-point format
//(with no exponent field)
<<setprecision(10)
//Set the stream's internal floating-point precision
<<pi<<endl;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -