Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

How to make a program in c that find sin value for any angle

0 votes
asked Jan 24, 2019 by niladridhar (120 points)

1 Answer

0 votes
answered Jan 25, 2019 by Bullwinkle

The C math library provides a sine function with the following prototype:

double sin( double x );

The angle 'x' is expressed in radians.  You'll find other trigonometric functions in the C math library also; consult the man pages and/or do an online search for more info.

To obtain access to the math library functions, you must do two things.  First, #include <math.h> into your source code file; otherwise you'll get a compiler error when you try to invoke sin().  Second, be sure to add the -lm option to your compiler command line so that the math library is included into your build; otherwise you'll get an "unknown symbol" error from the linker.


Sine Example:

#include <math.h>

/*
** Surprisingly, PI is not defined in math.h (if it's a conforming C
** implementation).  POSIX provides the M_PI symbol, which has the following
** value.
*/
#define PI 3.14159265358979323846

int main( void )
{
   printf( "The sine of pi/4 is %lf.\n", sin(PI/4) );
   return 0;
}


Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...