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