Thursday, November 22, 2012

C PROGRAM FOR COSINE SERIES


/*C PROGRAM FOR  COSINE SERIES */

#include<stdio.h>
#include<conio.h>
#include<math.h>
#define pi 3.14

void main()
{
    int n,i,j;
    float x,x1,sum,p,f,k;
    clrscr();
    printf("\n\tCOSINE SERIES");
    printf("\n\t~~~~~~~~~~~~~~~");
    printf("\nEnter the value of n:");
    scanf("%d",&n);
    printf("\nEnter the value for x:");
    scanf("%f",&x);
    x1=x*(pi/180);
    sum=1;

for(i=2;i<=n*2;i+=2)
{
     p=pow(x1,i);
     f=1;

for(j=1;j<i;j++)
{
     f=f*j;
}
     k=1;
     k=k*(-1);
     sum=sum+(p/f)*k;
}
     printf("\n The sum of series %f",sum);
     printf("\n The cosine series:%f",cos(x1));
     getch();
}









OUTPUT:

        COSINE SERIES
        ~~~~~~~~~~~~~~
Enter the value of n: 2

Enter the value for x: 4

 The sum of series: 0.995127
 The cosine series: 0.997567



0 comments:

Post a Comment