C++ program to find sinx and cosx trigonometric values using predefined functions

Hey coders! Here, we are going to discuss a tutorial on the calculation of sinx and cosx values in C++. Here, the value of the angle will be given as input in radians, for which sinx and cosx values will be calculated using predefined methods available in C++. So, let’s dive into its method, algorithm, and code along with its output.

Method: find sin(x) and cos(x)

In general, we use a trigonometric table that consists of sinx, cosx values, and others. But, did you ever think of how did we get those values in programming? Yeah, you are on the correct blog!. We are now going to see the functions used for sinx and cosx values in C++.

Algorithm/Steps to be followed:

1. We use math.h header file for trigonometric values.

2. This header file must be included in the program.

3. Inputs to the functions will be taken in radians, but not in degrees.

4. Sinx formula: sin(x)

5. Cosx formula: cos(x)

 

C++ Code to find value of sin x and cos x

// C++ program to illustrate sinx and cosx trigonometric functions

#include <iostream> 
#include <math.h>   // math.h header file included
using namespace std;
  
int main()
{
    double n;
    cout<<"Enter input radian angle value : ";
    cin>>n;
    cout << "Sine value of " << n << " : " << sin(n) << endl;
    cout << "Cosine value of " << n << " : " << cos(n) << endl;

    return 0;
}

 

Output:

Enter input radian angle value : 1.4
Sine value of 1.4 : 0.98545
Cosine value of 1.4 : 0.169967

Similar tutorial:

In the above article, we discussed the calculation of sinx and cosx. You can refer to this blog for using more trigonometric functions: C++ program to build a trigonometric calculator

 

Conclusion:

Hopefully, practice more problems and try out other trigonometric functions too.

Happy coding!

Leave a Reply

Your email address will not be published.