/* To evaluate the value of Cosx */
#include<stdio.h>
#include<math.h>
int main()
{
int i, n;
float x, sum, t, x1;
/*n=counting upto n terms in expansion of cosx series*/
printf("Enter the value of x in degree & n:\n");
scanf("%f%d", &x, &n);
x1=x;
/*To convert the angle from degree to Radian*/
x=x*3.14159/180;
sum=1;
t=1;
for(i=1;i<=(n-1);i++)
{
t=-t*x*x/((2*i-1)*2*i);
sum=sum+t;
}
printf("Cos(%f)=%f\n",x1,sum);
return(0);
}
#include<stdio.h>
#include<math.h>
int main()
{
int i, n;
float x, sum, t, x1;
/*n=counting upto n terms in expansion of cosx series*/
printf("Enter the value of x in degree & n:\n");
scanf("%f%d", &x, &n);
x1=x;
/*To convert the angle from degree to Radian*/
x=x*3.14159/180;
sum=1;
t=1;
for(i=1;i<=(n-1);i++)
{
t=-t*x*x/((2*i-1)*2*i);
sum=sum+t;
}
printf("Cos(%f)=%f\n",x1,sum);
return(0);
}
Comments
Post a Comment