Ads by ProfitSence
Close

C++ sin()

Last Updated on Sunday 9th Oct 2022

The C++ sin() function returns the sine of an angle given in radians. It is defined in <cmath> header file.

Syntax

			
					sin(x)

			
	

Parameters

The sin() function takes a one argument in radians.

Return value

The sin() function returns the value in the range of [-1, 1].Return value sine of x radians. Value is either in double, float, or long double.

sin() prototype [As of C++ 11 standard]

			
					double sin(double x);
float sin(float x);
long double sin(long double x);
double sin (T x); // For integral type

			
	

Example 1: C++ sin()

			
					#include <stdio.h>
#include <math.h>

#define PI 3.14159265
int main () {
  double param, result;
  param = 11.0;
  result = sin (param * PI/180);
  printf ("The sine of %f degrees is %f.\n", param, result );
  return 0;
}

			
	

Output

			
					The sine of 11.000000 degrees is 0.190809.

			
	

Example 2: With Negative Value

			
					#include <stdio.h>
#include <math.h>

#define PI 3.14159265
int main () {
  double param, result;
  // With Negative value
  param = -22.0;
  result = sin (param * PI/180);
  printf ("The sine of %f degrees is %f.\n", param, result );
  return 0;
}

			
	

Output

			
					The sine of -22.000000 degrees is -0.374607.

			
	

Example 3: C++ code with integral type

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

int main() {
  int x = -4;
  double result;
  result = sin(x);
  cout << "sin(x) = " << result << endl;
  return 0;
}

			
	

Output

			
					sin(x) = 0.756802

			
	

References