C++ | Trigonometric functions














































C++ | Trigonometric functions



 The C++ <cmath> header file declares a set of functions to perform mathematical   operations such as the elementary exponential, logarithm, square root, and trigonometric   functions etc.
 Note:- All the functions take input in radians and not degrees
 1. sin( ) - This function takes angle (in radians) as an argument and returns its sine value.
         Syntax :- float sin(float x);
                         double sin(double x);
                         long double sin(long double x);
                         double sin (T x);  ( for integral type )

         Parameter :- The sin() function takes a single mandatory argument in radians.

         Return value :- The sin() function returns the value in the range of [-1, 1]. The                                                  returned value is either in double, float, or long double.

 2. cos( ) - This function takes angle (in radians) as an argument and returns its cosine value.
         Syntax :- double cos(double x);
                         float cos(float x);
                         long double cos(long double x);
                         double cos(T x); ( Here, T is an integral type )

         Parameter :- The cos() function takes a single mandatory argument in radians.

         Return value :- The cos() function returns the value in the range of [-1, 1]. The                                                 returned value is either in double, float, or long double.

 3. tan( ) - This function takes angle (in radians) as an argument and returns its tangent                          value.
         Syntax :- double tan(double x);
                         float tan(float x);
                         long double tan(long double x);
                         double tan (T x);  ( for integral type )

         Parameter :- The tan() function takes a single mandatory argument in radians.

         Return value :- The tan() function returns the value in the range of [-∞, ∞].

 Code of Trigonometric functions all together :
#include <iostream>
#include <cmath>
using namespace std;

int main() {
double x;
cout << "Enter the value of number x : ";
cin >> x;
cout << "Sine value of x = " << x << " is => " << sin(x) << endl;
cout << "Cosine value of x = " << x << " is => " << cos(x) << endl;
cout << "Tangent value of x = " << x << " is => " << tan(x) << endl;
return 0;
}


Output:-
Enter the value of number x : 5.2
Sine value of x = 5.2 is => -0.883455
Cosine value of x = 5.2 is => 0.468517
Tangent value of x = 5.2 is => -1.88564


Comments