Hit enter after type your search item

C++ sin() function [3 Examples]

The sin function in C++

  • sin() is the built-in function in C++
  • This function is defined in the <cmath> library – you have to include this in the header in order to use it.
  • The sin() function takes one argument i.e. a number which is angle and it returns the sine of angle x radians.
  • The return value is of double type i.e. sine of the given argument x (radians)

Syntax of sin() function


An example of using sin() function

In the first example, we simply provide a value to the sin() function and assign the return value to a double-type variable. Then we displayed the result as follows:



Taking user input for sin()

As you run this C++ program, it asks you to enter the angle given in radians. Then sin() function is used to get the sine and we will display the result:

Sample result:


Using negative value example

For this example, we assigned a negative value to the sin() function.




This div height required for enabling the sticky sidebar