C++ program to demonstrate the use of math constants
kw.cpp
#include<iostream>
#include<cmath>usingnamespacestd;intmain(){cout<<"———————————————————————————————————————————";cout<<"\nProgram to use the math library functions";cout<<"\n———————————————————————————————————————————";cout<<"\nValue of PI | "<<M_PI;cout<<"\nValue of PI/2 | "<<M_PI_2;cout<<"\nValue of PI/4 | "<<M_PI_4;cout<<"\nValue of 1/PI | "<<M_1_PI;cout<<"\nValue of 2/PI | "<<M_2_PI;cout<<"\nValue of log2e | "<<M_LOG2E;cout<<"\nValue of log10e | "<<M_LOG10E;cout<<"\nValue of Nlog2 | "<<M_LN2;cout<<"\nValue of Nlog10 | "<<M_LN10;cout<<"\nValue of sqrt(1/2) | "<<M_SQRT2;cout<<"\nValue of 1/sqrt(2) | "<<M_SQRT1_2;cout<<"\nValue of 2/sqrt(PI) | "<<M_2_SQRTPI;cout<<"\nPositive Infinity | "<<HUGE_VAL;cout<<"\n———————————————————————————————————————————\n";return0;}
Output
kodingwindow@kw:~$ g++ kw.cpp kodingwindow@kw:~$ ./a.out
———————————————————————————————————————————
Program to use the math library functions
———————————————————————————————————————————
Value of PI | 3.14159
Value of PI/2 | 1.5708
Value of PI/4 | 0.785398
Value of 1/PI | 0.31831
Value of 2/PI | 0.63662
Value of log2e | 1.4427
Value of log10e | 0.434294
Value of Nlog2 | 0.693147
Value of Nlog10 | 2.30259
Value of sqrt(1/2) | 1.41421
Value of 1/sqrt(2) | 0.707107
Value of 2/sqrt(PI) | 1.12838
Positive Infinity | inf
———————————————————————————————————————————
kodingwindow@kw:~$
Dear User, Thank you for visitng KodingWindow. If you are interested in technical articles, latest technologies, and our journey further, please follow us on LinkedIn.