Program to compute sin(x) through series summation

#define PI 3.14
#include <stdio.h>
#include <math.h>
main()
{
 /*Program to compute sin(x) through series summation*/
 float x=0, sum=0, term=0;
 int sign=1, den=1;
 printf("\nEnter the angle in degrees: ");
 scanf("%f", &x);
 x=(PI/180)*x;
 term = x;
 while(fabs(term) >= 0.000001)
 {
  sum = sum + (term*sign);
  term = (term*x*x)/((den+1)*(den+2));
  sign = sign*(-1);
  den = den + 2;
 }
 printf("\nThrough series summation   sin(%f) = %f", x, sum);
 printf("\nThrough sine function call sin(%f) = %f", x, sin(x));
}
Advertisements
This entry was posted in Information Technology. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s