Google Ads

Wednesday, May 27, 2009

Cosine Series

SUMMATION OF COSINE SERIES

#include”stdio.h”
#include “conio.h”
#include
int fact(int);
void main()
{
int i,j,x;
float sum=1,x1,n,c=1,p,f;
clrscr();
printf("\n Enter the values of x and n : ");
scanf("%d %f",&x,&n);
x1=(x*3.14)/180;
for(i=2;i<=n;i=i+2)
{
p=pow(x1,i);
f=fact(i);
c=c*(-1);
c=c*(p/f);
sum=sum+c;
}
printf("\n Summation of Cosine Series : %.4f",sum);
printf("\n\n Cos(%d) : %.4f",x,cos(x1));
getch();
}


int fact(int a)
{
int f=1,i;
for(i=1;i<=a;i++)
f=f*i;
return(f);
}

Output will be

Enter the values of x and n : 30 6

Summation of Cosine Series : 0.8635

Cos(30) : 0.8662

No comments:

Post a Comment