C math library function sin()


In this tutorial, you will learn about C math library function sin() that computes the sine of the argument.

C math library function sin()

sin() is the built in standard math library function that is defined in math library math.h.

#include<math.h>

Function prototype of C math library function sin()

double sin( double x );

where,

x = angle in radians ( floating point value )

Return Value of sin()

This function returns the sine value of x.

The return type is double and ranges between 1 and -1.

Example: Program to demonstrate the use of C math library function sin( )

/*Use of math library function cos()*/

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

#define PI 3.1415926

int main()
{
   double x ;

   x = 45;
   //calculation of sine
   printf("\nsin( %.3lf ) = %.3lf\n", x, sin( (x * PI) / 180 ));

   x = 90;
   //calculation of sine
   printf("\nsin( %.3lf ) = %.3lf\n", x, sin( (x * PI) / 180 ));

   x = 120;
   //calculation of sine
   printf("\nsin( %.3lf ) = %.3lf\n", x, sin( (x * PI) / 180 ));

   return 0;
}

Output

c math function sin

Explanation

In the above program, we have calculated the sine of x.