C++ Program to Illustrate Trigonometric functions - GeeksforGeeks

18 May, 2020
The math.h header contains methods for performing basic numeric operations such as the elementary exponential, logarithm, square root, and trigonometric functions. In order to use these functions you need to include header file math.h.Note: All the functions take input in radians and not degrees
Below are the various trigonometric functions that can be used from the math.h header:
sin: This function takes angle (in radians) as an argument and returns its sine value that could be verified using a sine curve.Example:// C++ program to illustrate// sin trigonometric function  #include <iostream>#include <math.h>using namespace std;  int main(){    double x = 2.3;    cout << "Sine value of x = 2.3: "         << sin(x) << endl;      return 0;}Output:Sine value of x = 2.3: 0.745705
cos: This function takes angle (in radians) as an argument and return its cosine value that could be verified using cosine curve.Example:// C++ program to illustrate// cos trigonometric function  #include <iostream>#include <math.h>using namespace std;  int main(){    double x = 2.3;      cout << "Cosine value of x = 2.3: "         << cos(x) << endl;      return 0;}Output:Cosine value of x = 2.3: -0.666276
tan: This function takes angle (in radians) as an argument and return its tangent value. This could also be verified using Trigonometry as Tan(x) = Sin(x)/Cos(x).Example:// C++ program to illustrate// tan trigonometric function  #include <iostream>#include <math.h>using namespace std;  int main(){    double x = 2.3;    cout << "Tangent value of x = 2.3: "         << tan(x) << endl;      return 0;}Output:Tangent value of x = 2.3: -1.11921
acos: This function returns the arc cosine of argument. The argument to acos must be in the range -1 to 1; otherwise, a domain error occurs.Example:// C++ program to illustrate// acos trigonometric function  #include <iostream>#include <math.h>using namespace std;  int main(){    double x = 1.0;    cout << "Arc Cosine value of x = 1.0: "         << acos(x) << endl;      return 0;}Output:Arc Cosine value of x = 1.0: 0
asin: This function returns the arcsine of argument. The argument to asin must be in the range -1 to 1; otherwise, a domain error occurs.Example:// C++ program to illustrate// asin trigonometric function  #include <iostream>#include <math.h>using namespace std;  int main(){    double x = 1.0;    cout << "Arc Sine value of x = 1.0: "         << asin(x) << endl;      return 0;}Output:Arc Sine value of x = 1.0: 1.5708
atan: This function returns the arc tangent of arg.Example:// C++ program to illustrate// atan trigonometric function  #include <iostream>#include <math.h>using namespace std;  int main(){    double x = 1.0;    cout << "Arc Tangent value of x = 1.0: "         << atan(x) << endl;      return 0;}Output:Arc Tangent value of x = 1.0: 0.785398
atan2: This function returns the arc tangent of (a)/(b).Example:// C++ program to illustrate// atan2 trigonometric function  #include <iostream>#include <math.h>using namespace std;  int main(){    double x = 2.3, y = 1.0;    cout << "Arc Tangent 2 value of x = 2.3 and y = 1.0: "         << atan2(x, y) << endl;      return 0;}Output:Arc Tangent 2 value of x = 2.3 and y = 1.0: 1.16067
cosh: This function returns the hyperbolic cosine of argument provided. The value of the argument provided must be in radians.Example:// C++ program to illustrate// cosh trigonometric function  #include <iostream>#include <math.h>using namespace std;  int main(){    double x = 57.3; // in degrees    cout << "Hyperbolic Cosine of x=57.3: "         << cosh(x) << endl;      return 0;}Output:Hyperbolic Cosine of x=57.3: 3.83746e+24
tanh: This function returns the hyperbolic tangent of argument provided. The value of argument provided must be in radians.Example:// C++ program to illustrate// tanh trigonometric function  #include <iostream>#include <math.h>using namespace std;  int main(){    double x = 57.3; // in degrees    cout << "Hyperbolic Tangent of x=57.3: "         << tanh(x) << endl;      return 0;}Output:Hyperbolic Tangent of x=57.3: 1

sin: This function takes angle (in radians) as an argument and returns its sine value that could be verified using a sine curve.Example:// C++ program to illustrate// sin trigonometric function  #include <iostream>#include <math.h>using namespace std;  int main(){    double x = 2.3;    cout << "Sine value of x = 2.3: "         << sin(x) << endl;      return 0;}Output:Sine value of x = 2.3: 0.745705

Example:
// C++ program to illustrate// sin trigonometric function  #include <iostream>#include <math.h>using namespace std;  int main(){    double x = 2.3;    cout << "Sine value of x = 2.3: "         << sin(x) << endl;      return 0;}
Sine value of x = 2.3: 0.745705

cos: This function takes angle (in radians) as an argument and return its cosine value that could be verified using cosine curve.Example:// C++ program to illustrate// cos trigonometric function  #include <iostream>#include <math.h>using namespace std;  int main(){    double x = 2.3;      cout << "Cosine value of x = 2.3: "         << cos(x) << endl;      return 0;}Output:Cosine value of x = 2.3: -0.666276

Example:
// C++ program to illustrate// cos trigonometric function  #include <iostream>#include <math.h>using namespace std;  int main(){    double x = 2.3;      cout << "Cosine value of x = 2.3: "         << cos(x) << endl;      return 0;}
Cosine value of x = 2.3: -0.666276

tan: This function takes angle (in radians) as an argument and return its tangent value. This could also be verified using Trigonometry as Tan(x) = Sin(x)/Cos(x).Example:// C++ program to illustrate// tan trigonometric function  #include <iostream>#include <math.h>using namespace std;  int main(){    double x = 2.3;    cout << "Tangent value of x = 2.3: "         << tan(x) << endl;      return 0;}Output:Tangent value of x = 2.3: -1.11921

Example:
// C++ program to illustrate// tan trigonometric function  #include <iostream>#include <math.h>using namespace std;  int main(){    double x = 2.3;    cout << "Tangent value of x = 2.3: "         << tan(x) << endl;      return 0;}
Tangent value of x = 2.3: -1.11921

acos: This function returns the arc cosine of argument. The argument to acos must be in the range -1 to 1; otherwise, a domain error occurs.Example:// C++ program to illustrate// acos trigonometric function  #include <iostream>#include <math.h>using namespace std;  int main(){    double x = 1.0;    cout << "Arc Cosine value of x = 1.0: "         << acos(x) << endl;      return 0;}Output:Arc Cosine value of x = 1.0: 0

Example:
// C++ program to illustrate// acos trigonometric function  #include <iostream>#include <math.h>using namespace std;  int main(){    double x = 1.0;    cout << "Arc Cosine value of x = 1.0: "         << acos(x) << endl;      return 0;}
Arc Cosine value of x = 1.0: 0

asin: This function returns the arcsine of argument. The argument to asin must be in the range -1 to 1; otherwise, a domain error occurs.Example:// C++ program to illustrate// asin trigonometric function  #include <iostream>#include <math.h>using namespace std;  int main(){    double x = 1.0;    cout << "Arc Sine value of x = 1.0: "         << asin(x) << endl;      return 0;}Output:Arc Sine value of x = 1.0: 1.5708

Example:
// C++ program to illustrate// asin trigonometric function  #include <iostream>#include <math.h>using namespace std;  int main(){    double x = 1.0;    cout << "Arc Sine value of x = 1.0: "         << asin(x) << endl;      return 0;}
Arc Sine value of x = 1.0: 1.5708

atan: This function returns the arc tangent of arg.Example:// C++ program to illustrate// atan trigonometric function  #include <iostream>#include <math.h>using namespace std;  int main(){    double x = 1.0;    cout << "Arc Tangent value of x = 1.0: "         << atan(x) << endl;      return 0;}Output:Arc Tangent value of x = 1.0: 0.785398

Example:
// C++ program to illustrate// atan trigonometric function  #include <iostream>#include <math.h>using namespace std;  int main(){    double x = 1.0;    cout << "Arc Tangent value of x = 1.0: "         << atan(x) << endl;      return 0;}
Arc Tangent value of x = 1.0: 0.785398

atan2: This function returns the arc tangent of (a)/(b).Example:// C++ program to illustrate// atan2 trigonometric function  #include <iostream>#include <math.h>using namespace std;  int main(){    double x = 2.3, y = 1.0;    cout << "Arc Tangent 2 value of x = 2.3 and y = 1.0: "         << atan2(x, y) << endl;      return 0;}Output:Arc Tangent 2 value of x = 2.3 and y = 1.0: 1.16067

Example:
// C++ program to illustrate// atan2 trigonometric function  #include <iostream>#include <math.h>using namespace std;  int main(){    double x = 2.3, y = 1.0;    cout << "Arc Tangent 2 value of x = 2.3 and y = 1.0: "         << atan2(x, y) << endl;      return 0;}
Arc Tangent 2 value of x = 2.3 and y = 1.0: 1.16067

cosh: This function returns the hyperbolic cosine of argument provided. The value of the argument provided must be in radians.Example:// C++ program to illustrate// cosh trigonometric function  #include <iostream>#include <math.h>using namespace std;  int main(){    double x = 57.3; // in degrees    cout << "Hyperbolic Cosine of x=57.3: "         << cosh(x) << endl;      return 0;}Output:Hyperbolic Cosine of x=57.3: 3.83746e+24

Example:
// C++ program to illustrate// cosh trigonometric function  #include <iostream>#include <math.h>using namespace std;  int main(){    double x = 57.3; // in degrees    cout << "Hyperbolic Cosine of x=57.3: "         << cosh(x) << endl;      return 0;}
Hyperbolic Cosine of x=57.3: 3.83746e+24

tanh: This function returns the hyperbolic tangent of argument provided. The value of argument provided must be in radians.Example:// C++ program to illustrate// tanh trigonometric function  #include <iostream>#include <math.h>using namespace std;  int main(){    double x = 57.3; // in degrees    cout << "Hyperbolic Tangent of x=57.3: "         << tanh(x) << endl;      return 0;}Output:Hyperbolic Tangent of x=57.3: 1

Example:
// C++ program to illustrate// tanh trigonometric function  #include <iostream>#include <math.h>using namespace std;  int main(){    double x = 57.3; // in degrees    cout << "Hyperbolic Tangent of x=57.3: "         << tanh(x) << endl;      return 0;}
Hyperbolic Tangent of x=57.3: 1

Below are the trigonometric functions all together:
// C++ program to illustrate some of the// above mentioned trigonometric functions  #include <iostream>#include <math.h>using namespace std;  int main(){    double x = 2.3;    cout << "Sine value of x = 2.3: "         << sin(x) << endl;    cout << "Cosine value of x = 2.3: "         << cos(x) << endl;    cout << "Tangent value of x = 2.3: "         << tan(x) << endl;      x = 1.0;    cout << "Arc Cosine value of x = 1.0: "         << acos(x) << endl;    cout << "Arc Sine value of x = 1.0: "         << asin(x) << endl;    cout << "Arc Tangent value of x = 1.0: "         << atan(x) << endl;      x = 57.3; // in degrees    cout << "Hyperbolic Cosine of x=57.3: "         << cosh(x) << endl;    cout << "Hyperbolic tangent of x=57.3: "         << tanh(x) << endl;      return 0;}
Sine value of x = 2.3: 0.745705
Cosine value of x = 2.3: -0.666276
Tangent value of x = 2.3: -1.11921
Arc Cosine value of x = 1.0: 0
Arc Sine value of x = 1.0: 1.5708
Arc Tangent value of x = 1.0: 0.785398
Hyperbolic Cosine of x=57.3: 3.83746e+24
Hyperbolic tangent of x=57.3: 1

f20170200
CPP-Functions
C++ Programs
Geometric
Geometric
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
C++ Program for QuickSort
Shallow Copy and Deep Copy in C++
delete keyword in C++
Passing a function as a parameter in C++
cin in C++
Closest Pair of Points using Divide and Conquer algorithm
How to check if a given point lies inside or outside a polygon?
Program for distance between two points on earth
How to check if two given line segments intersect?
Convex Hull | Set 1 (Jarvis's Algorithm or Wrapping)