All Functions OF Math.h Header File With Example IN C++: by Code Seekers
All Functions OF Math.h Header File With Example IN C++: by Code Seekers
ALL FUNCTIONS
OF math.h
HEADER FILE
WITH EXAMPLE
IN C++
By Code Seekers
https://web.facebook.com/c0deSeekeRs
1
[email protected].
Code:
1. #include <iostream>
2. #include <math.h>
3. using namespace std;
4. #define PI 3.14159
5. int main ()
6. {
7. double x, ans;
13. return(0);
14. }
https://web.facebook.com/c0deSeekeRs
2
[email protected].
Code:
1. #include <iostream>
2. #include <math.h>
3. using namespace std;
4. #define PI 3.14159
5. int main ()
6. {
7. double x;
8. cout<<"\n\tEnter Angle to find cos , sin, tan : ";
9. cin>>x;
10. cout<<"\n\tCos"<<x<<" = "<< cos(x * PI/180.0) <<endl;
11. cout<<"\n\tSin"<<x<<" = "<< sin(x * PI/180.0)<<endl;
12. cout<<"\n\tTan"<<x<<" = "<< tan(x * PI/180.0)<<endl;
13. return(0);
14. }
https://web.facebook.com/c0deSeekeRs
3
[email protected].
Code:
1. #include <iostream>
2. using namespace std;
3. #include <math.h>
4. int main () {
5. double x;
6. cout<<"\n\tEnter value of x to find coshx, sinhx, tanhx : ";
7. cin>>x;
8. //coshx hyperbolic cos of x
9. cout<<"\n\tThe hyperbolic cosine of "<<x<<" = "<<cosh(x);
10. //sinhx hyperbolic sin of x
11. cout<<"\n\n\tThe hyperbolic sine of "<<x<<" = "<<sinh(x);
12. //tanhx hyperbolic tan of x
13. cout<<"\n\n\tThe hyperbolic tangent of"<<x<<" = "<<tanh(x);
14. return 0;
15. }
https://web.facebook.com/c0deSeekeRs
4
[email protected].
• SYNTAX
o Double exp(double x);
o This function double exp(double x) returns the value of e raised to the xth
power.
CODE:
1. #include <iostream>
2. using namespace std;
3. #include <math.h>
4. int main () {
a. double x;
b. cout<<"\n\tEnter power x : ";
c. cin>>x;
d. cout<<"\n\tThe exponential value of "<< x<<" = "<<exp(x)<<endl;
5. return(0);
6. }
https://web.facebook.com/c0deSeekeRs
5
[email protected].
• SYNTAX
o double log(double x)
o this function double log(double x) returns the natural logarithm (base-e
logarithm) of x.
o double log10(double x)
o This function double log10(double x) returns the common logarithm (base-10
logarithm) of x.
CODE:
1. #include <iostream>
2. using namespace std;
3. #include <math.h>
4. int main () {
a. double x;
b. cout<<"\n\tEnter x : ";
c. cin>>x;
d. cout<<"\n\tln ( "<< x<<" ) = "<<log(x)<<endl;
e. cout<<"\n\tlog ( "<< x<<" ) = "<<log10(x)<<endl;
5. return(0);
6. }
https://web.facebook.com/c0deSeekeRs
6
[email protected].
CODE:
1. #include <iostream>
2. using namespace std;
3. #include<math.h>
4. int main () {
5. double x, fpart, intpart;
a. cout<<"\n\tEnter x : ";
b. cin>>x;
6. fpart = modf(x, &intpart);
7. cout<<"\n\tIntegral part = "<< intpart<<endl;
8. cout<<"\n\tFraction Part = "<< fpart<<endl;
9. return(0);
10. }
https://web.facebook.com/c0deSeekeRs
7
[email protected].
CODE:
1. #include <iostream>
2. using namespace std;
3. #include<math.h>
4. int main () {
5. double x,y;
a. cout<<"\n\tEnter x : ";
b. cin>>x;
c. cout<<"\n\tEnter y : ";
d. cin>>y;
e. cout<<"\n\t "<<x<<" ^ "<<y<<" = "<<pow(x,y)<<endl;
6. return 0;
7. }
https://web.facebook.com/c0deSeekeRs
8
[email protected].
CODE:
1. #include <iostream>
2. using namespace std;
3. #include<math.h>
4. int main () {
5. double x;
6. cout<<"\n\tEnter x : ";
7. cin>>x;
8. cout<<"\n\t "<<char(251)<<x<<" = "<<sqrt(x)<<endl;
9. return(0);
10. }
https://web.facebook.com/c0deSeekeRs
9
[email protected].
CODE:
1. #include <iostream>
2. using namespace std;
3. #include<math.h>
4. int main ()
5. {
6. double x;
a. cout<<"\n\tEnter x : ";
b. cin>>x;
c. cout<<"\n\t smaller integer value nearest to "<<x<<" = "<<floor(x)<<endl;
d. cout<<"\n\t larger integer value nearest to "<<x<<" = "<<ceil(x)<<endl;
7. return(0);
8. }
https://web.facebook.com/c0deSeekeRs
10
[email protected].
CODE:
1. #include <iostream>
2. using namespace std;
3. #include<math.h>
4. int main ()
5. {
6. double x,y;
a. cout<<"\n\tEnter x : ";
b. cin>>x;
c. cout<<"\n\tEnter y : ";
d. cin>>y;
e. cout<<"\n\tModulus of "<<x<<" / "<<y<<" = "<<fmod(x,y)<<endl;
7. return(0);
8. }
https://web.facebook.com/c0deSeekeRs
11
[email protected].
CODE:
1. #include <iostream>
2. using namespace std;
3. #include<math.h>
4. int main ()
5. {
6. double x;
a. cout<<"\n\tEnter x : ";
b. cin>>x;
c. cout<<"\n\tAbsolute of "<<x<<" = "<<fabs(x)<<endl;
7. return(0);
8. }
https://web.facebook.com/c0deSeekeRs
12
[email protected].
Website:
https://programcodescpp.wixsite.com/programcodes
Email:
[email protected]
Facebook Page:
https://web.facebook.com/c0deSeekeRs
YouTube Channel
https://www.youtube.com/channel/UCfizosx-0fkFJ6R-oF6l9-A?view_as=subscriber
https://web.facebook.com/c0deSeekeRs
13