In this C++ tutorial, you will learn how to find the sine of an angle using sin() function of cmath, with syntax and examples.

C++ sin()

C++ sin() function returns sine of an angle given in radians. Angle is passed as an argument to sin().

Syntax

The syntax of C++ sin() is

</>
Copy
sin(x)

where

ParameterDescription
xAngle in radians.

Returns

Return value depends on the type of value passed for parameter x. The return value of sin(x) is

  • double if x is double.
  • float if x is float.
  • long double if x is long double.

The synopsis of sin() function is

</>
Copy
double sin(double x);
float sin(float x);
long double sin(long double x);
double sin(T x); // for integral type argument values

sin() is a function of cmath library. Include cmath library in the program, if using sin().

Example

In this example, we read x value from user and find the sine of this angle using sin() function.

C++ Program

</>
Copy
#include <iostream>
#include<cmath>
using namespace std;

int main() {
    double x;
    cout << "Enter angle (in radians) : ";
    cin >> x;
    
    double result = sin(x);
    cout << "sin(" << x << ") : " << result << endl;
}

Output

Enter angle (in radians) : 1.2
sin(1.2) : 0.932039
Program ended with exit code: 0
Enter angle (in radians) : 0
sin(0) : 0
Program ended with exit code: 0

Conclusion

In this C++ Tutorial, we learned the syntax of C++ sin(), and how to use this function to find sine of given angle, with the help of examples.