#include <math.h>
#define PI acos(-1)
主要是利用利用数学函数中的反三角函数,但是要注意一定引入math包
arccos(−1)=π\arccos(-1)=\piarccos(−1)=π
完整示例:
//#define LOCAL
#include <iostream>
#include <stdio.h>
#include <math.h>
using namespace std;
#define PI acos(-1)
int main()
{
printf("%.30lf\n",PI);
return 0;
}
结果:

位数一般够了。
本文介绍了一种利用C++中的math包和反三角函数计算π值的方法,通过定义宏PI并将其设置为acos(-1)的值来实现,示例代码展示了如何在程序中输出π值到小数点后30位。
7995

被折叠的 条评论
为什么被折叠?



