C++ Standard Library C++ STL Library

C++ <cmath> - sin() Function



The C++ <cmath> sin() function returns trigonometric sine of an angle (angle should be in radians). In the graph below, sin(x) vs x is plotted.

Sin Function

Syntax

double sin (double x);
float sin (float x);
long double sin (long double x);
double sin (double x);
float sin (float x);
long double sin (long double x);
//additional overloads for integral types
double sin (T x);           

Parameters

x Specify the angle in radian.

Return Value

Returns the trigonometric sine of an angle.

Example:

In the example below, sin() function is used to find out the trigonometric sine of an angle.

#include <iostream>
#include <cmath>
using namespace std;
 
int main (){
  //M_PI - value of PI from math.h
  cout<<sin(M_PI/6)<<"\n";
  cout<<sin(M_PI/4)<<"\n";
  cout<<sin(M_PI/3)<<"\n";
  return 0;
}

The output of the above code will be:

0.5
0.707107
0.866025

❮ C++ <cmath> Library