c++ pi constant code example
Example 1: pi in c++
#define _USE_MATH_DEFINES // must include this!
#include
#include
int main() {
// M_PI = 3.14159265358979323846;
std::cout << M_PI << " " << M_E << " " << M_SQRT2 << endl;
return 0;
}
Example 2: c++ pi float
const float pi = 2 * acos(0.0f);
Example 3: long pi in c++
typedef long double ld;
const ld pi = 3.1415926535897932384626433832795;
Example 4: c++ constant
#define LENGTH 10
#define WIDTH 5
#define NEWLINE '\n'