C/C++中使用PI(π)


2两方法:

  1. 使用math中的宏定义M_PI;
  2. 利用arccos(-1) = π,来计算π值;
#include <iostream>
#include <iomanip>
#define _USE_MATH_DEFINES // 使用math.h中的M_PI宏定义需要
#include <math.h>

using namespace std;
int main()
{
	double pi1 = M_PI;
	cout << setprecision(30) << "pi1 = "  << pi1 << endl;

	double pi2 = acos(-1);
	cout <<  "pi2 = " << pi2 << endl;
        return 0;
}

运行结果:

pi1 = 3.141592653589793115997963468544185161590576171875
pi2 = 3.141592653589793115997963468544185161590576171875


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM