Name

sin

Synopsis

Calculates the sine of an angle

#include <math.h>
doublesin( double x );
double sinf( float x );        (C99)
double sinl( long double x );        (C99)

The sin() function calculates the sine of the angle represented by its argument x as a number of radians. The return value is in the range -1sin(x) ≤ 1.

Example

#define DEG_PER_RAD ( 180.0 / PI )

const double PI = 4.0 * atan( 1.0 );
double a[4];

printf( "\nEnter an acute angle measure, in degrees: " );

if ( scanf( "%lf", a ) < 1 ||  ( a[0] <= 0 || a[0] >= 90 ) )
  printf( "\nThat's not an acute angle.\n" ), exit( 1 );
else
{
  a[1] = a[0] + 90 ;
  a[2] = 180 − a[0] ;
  a[3] = 225 + a[0] ;
  for ( int i = 0 ; i < 4 ; i ++ )
    printf( "The sine of %4.2lf degrees is %6.4lf.\n",
            a[i], sin( a[i] / DEG_PER_RAD ) );
}

Get C in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.