Open In App

# C++ Program to Illustrate Trigonometric functions

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:

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 ``#include ``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
```
2. 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 ``#include ``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
```
3. 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 ``#include ``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
```
4. 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 ``#include ``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
```
5. 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 ``#include ``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
```
6. atan: This function returns the arc tangent of arg.

Example:

 `// C++ program to illustrate``// atan trigonometric function`` ` `#include ``#include ``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
```
7. atan2: This function returns the arc tangent of (a)/(b).

Example:

 `// C++ program to illustrate``// atan2 trigonometric function`` ` `#include ``#include ``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
```
8. 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 ``#include ``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
```
9. 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 ``#include ``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
```

Below are the trigonometric functions all together:

 `// C++ program to illustrate some of the``// above mentioned trigonometric functions`` ` `#include ``#include ``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;``}`

Output:

```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
```