Math Sin Function - C++ Programming Tutorial
C++ Course / Math Functions / Math Sin Function

Math Sin Function

BLUF: Mastering Math Sin Function is a critical step in becoming a proficient C++ developer. This lesson provides a deep dive into the syntax, performance considerations, and real-world applications of this concept.
Key Performance Insight: Math Sin Function

C++ is renowned for its efficiency. Learn how Math Sin Function enables low-level control and high-performance computing in the tutorial below.

C++ Math sin

The function is utilized to calculate the sine of an angle provided in radians.

Syntax

Consider a radian 'x'. Syntax would be:

Example

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

Note: If the value passed is an integer type, then it is cast to double.

Parameter

x : The value specified in terms of radian.

Return value

It provides the sine value of an angle specified in radians within the interval of [-1, 1].

Example 1

Let's observe a basic scenario where the value of x is greater than zero.

Example

#include <iostream>
#include<math.h>
using namespace std;
int main()
{
  double degree=60;
  double radian=degree*3.14/180;
  cout<<"Sine of an angle is : "<<sin(radian);
  return 0;
}

Output:

Output

Sine of an angle is : 0.86576

In this instance, the sin function computes the sine value of an angle with a measurement of 60 degrees.

Example 2

Let's examine a basic scenario where the value of x is below zero.

Example

#include <iostream>
#include<math.h>
using namespace std;
int main()
{
  double degree= -50;
  double radian=degree*3.14/180;
  cout<<"Sine of an angle is : "<<sin(radian);
  return 0;
}

Output:

Output

Sine of an angle is : -0.76576

In the provided illustration, the sin function calculates the sine of an angle in cases where the degree value is negative, such as -50.

Input Required

This code uses input(). Please provide values below:

Logic Practice
Install Logic Practice
Add to home screen for a faster app-like experience