C++ sin()

Yash-Var's avatar
Published Oct 8, 2022Updated Jun 20, 2023

The sin() function returns the sine of an angle argument, given in radians, in the range [-1,1].

  • Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
    • Includes 6 Courses
    • With Professional Certification
    • Beginner Friendly.
      75 hours
  • Learn C++ — a versatile programming language that’s important for developing software, games, databases, and more.
    • Beginner Friendly.
      11 hours

Syntax

sin(angle)

The angle parameter is expressed in radians.

Example

The following example illustrates the sin() function:

#include<iostream>
#include<math.h>
using namespace std;
int main() {
// convert degrees to radians
double pi = M_PI;
double degree = 60;
double radian = degree * pi/180;
cout << "Sine of 60 degrees is " << sin(radian) << "\n";
return 0;
}

This results in the following output:

Sine of 60 degrees is 0.866025

Codebyte Example

The following code example returns the sine of a angle given in radians using the sin() function.

Code
Output

All contributors

Learn C++ on Codecademy

  • Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
    • Includes 6 Courses
    • With Professional Certification
    • Beginner Friendly.
      75 hours
  • Learn C++ — a versatile programming language that’s important for developing software, games, databases, and more.
    • Beginner Friendly.
      11 hours