C++中表示pi的方法有两种
(1)
math库中利用arctan函数算出
tan(pi/4)=1;
pi=4*atan(1)
(2)
math库中已经定义好了pi的值
#define M_PI 3.14159265358979323846
可以直接用M_PI
两种方法获得的pi没有什么差别
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
int main()
{
printf("%0.100lf\n",atan(1)*4);
printf("%0.100lf\n",M_PI);
return 0;
}
output
3.1415926535897931159979634685441851615905761718750000000000000000000000000000000000000000000000000000
3.1415926535897931159979634685441851615905761718750000000000000000000000000000000000000000000000000000