Write A C Program To Find The Sum of
Write A C Program To Find The Sum of
#include<stdio.h>
#include<math.h>
void main()
{
int n,x1,i,j;
float x,sign,cosx,fact;
x1=x;
cosx=1;
sign=-1;
for(i=2;i<=n;i=i+2)
{
fact=1;
for(j=1;j<=i;j++)
{
fact=fact*j;
}
cosx=cosx+(pow(x,i)/fact)*sign;
sign=sign*(-1);
}
} /*End of main() */
/*--------------------------------------------------------
Output
Enter the number of the terms in aseries
5
Enter the value of x(in degrees)
60
Sum of the cosine series = 0.50
The value of cos(60) using library function = 0.499882
--------------------------------------------------------*/