What is the sin() function in C++?

Overview

In C++, the sin() function is used to return the sine of an angle of the argument x passed to it.

Syntax

double sin(double x);
float sin(float x);
long double sin(long double x);

Parameter

The sin() function takes only one parameter value x, which represents the value whose sine of angle in radian is to be determined.

Return value

The sin() function returns the sine of the angle in radian of the value of the parameter passed to it.

Code

#include <iostream>
#include <cmath>
using namespace std;
int main()
{
// creating the variables
int x = 90;
double result;
// implementing the sin() function
result = sin(x);
cout << "sin(90) = " << result << endl;
return 0;
}

Explanation

  • Lines 8–9: We create variables x and result.

  • Line 12: We implement the sin() function on the x variable and assign the value to the result variable.

  • Line 13: We print the result variable.

Free Resources