Sin() Function in C

Learn via video course
FREE
View all courses
C++ Course: Learn the Essentials
C++ Course: Learn the Essentials
by Prateek Narang
1000
5
Start Learning
C++ Course: Learn the Essentials
C++ Course: Learn the Essentials
by Prateek Narang
1000
5
Start Learning
Topics Covered

Overview

The sine (sin, in short) function in mathematics is a trigonometric function of an angle. In the C programming language, the <math.h> header file provides us with the sin() function. This function allows us to calculate the sin value of any given angle (in radians).

Syntax of Sin() Function in C

Following is the syntax of the sin function in C.

Here x is the angle in radians.

Parameters of Sin() Function in C

The sin function takes only one parameter -

  • x: double

Here x is the angle in radians (not degrees)

Return value of Sin() function in C

Return type: double

The sin function in C returns one value, the sine of an angle x. The return value ranges between -1 to +1, both inclusive.

Exceptions of Sin() Function in C

There are no exceptions of the sin function in C.

Example

Let us take a simple example to get an overview of the sin function in C.

Output of the above program:

In the above example, we imported the <math.h> header file so that we could use the sin() function and the M_PI constant (M_PI stores the value of pi). We created a variable x to store the value of an angle. Finally, we used sin(x) to calculate the sine of the variable x and then printed the value it returned.

What is sin() Function in C?

The sin() function takes an angle as an argument and returns the ratio of the length of the opposite side (or side opposite to the angle) of a right triangle to the length of its hypotenuse.

What is sin Function in C

sin(x) = opposite side (o) / hypotenuse (h)

Here is what the graph of the sin() function looks like: what io graph of the sin

More Examples

Example 1: Calculating sine of Zero, Positive, and Negative values

Output of the above example:

In this example, we used the sin() function to calculate the sine value of three different numbers - zero, a negative number, and a positive number. We used the printf() function to print out the values returned by the sin() function.

Example 2: Calculating sin() of an Angle in Degrees

If we have an angle in degrees, we can convert it into radians so that we could use the angle's value as an argument in the sin() function. We know that PI radians are equal to 180 degrees. So, we can use basic mathematics to convert degrees into radians.

Output of the above example:

In this example, we had an angle in degrees instead of radians. So, we converted degrees into radians and then used the angle in radians to calculate the sine value.

Conclusion

  • The sine function is a trigonometric function of angles.
  • The sin() function in C is used to calculate the sine value of any angle in radians.
  • The sin() function takes only one argument, the value of the angle.
  • The value returned by the sin() function ranges between -1 to +1 both inclusive.