Sum of sin series

Submitted by Karthikeyan on Sun, 06/09/2009 - 06:55

Sample C Program to find sin value of a given angle


/* Program to find sin value of a given angle */
/*Formula sin x = x/1! - x^3/3! + x^5/5! - x^7/7!*/

#include	 
#include	 
#define  	PI		3.1416
main( )
{
	int   f, 
		   i, 
		   j, 
		   n, 
		   sign = 1, 
		   xdeg;
	float xrad, 
		   xt, 
		   sinx = 0.0;
	printf( "\n\t\t Sum of sin series" );
	printf( "\n\t\t*******************\n" );
	printf( "\nEnter the value of angle and n " );
	scanf( "%d ", &xdeg );
	scanf( "%d", &n );
	xrad = xdeg * PI / 180;
	for( i = 1; i <= n; i = i + 2 )
	{
		for( f = 1, j = 1; j <= i; j++ )
			f = f * j;
		xt	 = pow( xrad, i ) / ( float )f;
		sinx = sinx + sign * xt;
		sign = -sign;
	}
	printf( "\n The sin value = %f", sinx );
	printf( "\n The use of library function sin in value = %f", sin( xrad ) );
	printf( "\n\n\t\t********************\n" );
	getch( );
}