SUMMATION OF SINE SERIES

/ *  SUMMATION OF SINE SERIES  */

#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
 {
    int x,n,t=1,i,j;
    double num,sum=0.0,r;
    long int deno;
    clrscr();
    printf("\n\t\tINPUT:");
    printf("\n\t\t------");
    printf("\n\t\tEnter the value for x:  ");
    scanf("%d",&x);
    printf("\n\t\tEnter the value for n:  ");
    scanf("%d",&n);
    printf("\n\t\tOUTPUT:");
    printf("\n\t\t-------");
    r=x*(3.14/180.0);
    printf("\n\t\tThe radius value for the given x value
                                            is:  %lf",r);
    for(i=1;i<=n;i+=2)
     {
       num=1.0;
       deno=1;
       for(j=1;j<=i;j++)
         {
           num=num*r;
           deno=deno*j;
         }
       sum=sum+num/deno*t;
       t=t*-1;
     }
    printf("\n\t\tThe value for sin %d is:  %lf",x,sum);
    printf("\n\t\tThe built-in value for given value is: 
                                             %lf",sin(r));
    getch();
  }


INPUT:
------
Enter the value for x:  30
Enter the value for n:  3

OUTPUT:
-------
The radius value for the given x value is:  0.523333
The value for sin 30 is:  0.499445
The built-in value for given value is:  0.499770



No comments:

Related Posts with Thumbnails