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 variablesint x = 90;double result;// implementing the sin() functionresult = sin(x);cout << "sin(90) = " << result << endl;return 0;}
Explanation
-
Lines 8–9: We create variables
xandresult. -
Line 12: We implement the
sin()function on thexvariable and assign the value to theresultvariable. -
Line 13: We print the
resultvariable.