Cosine Series ( cos(x)=1-x^2/2!+x^4/4!-x^6/6!+……………)

//c program to find the value of cosine series
#include<stdio.h>
#define pi 3.1416
void main()
{
int n,i;
float x, sum=0;
printf(“enter the value of angle in degree\n”);
scanf(“%f”,&x);                                                                    // x in degree
printf(“enter the value of n:”);
scanf(“%d”,&n);
x= pi*x/180;                                                                       // x in radian
float t1=1;
for(i=0;i<=n;i++)
{
sum+=t1;                                                              // logic for sin(x)=1-x^2/2!+x^4/4!-x^6/6!+……………
t1= t1*(-x*x)/((2*i+1)*(2*i+2));
}
printf(“Cos(x)=%f”,sum);
}

OUTPUT

Accuracy depends upon the value of n.

Leave a Reply

Your email address will not be published.