Write C program to implement cosine series using recursion.
#include<stdio.h>
#include<math.h>
main()
{
float x,sum;
int i,n,x1,t;
int fact(int);
printf("\n\n\t\t SUMMATION OF
COS(X)");
printf("\n\t\t
*************************\n");
printf("\nINPUT:");
printf("\n*******");
printf("\n Enter the
Degree:\n");
scanf("%d",&x1);
printf("\n Enter the Number of
Term:\n");
scanf("%d",&n);
x=(x1*3.14)/180;
t=-1;
sum=1;
for(i=2;i<=2*n;i+=2)
{
sum=sum+t*(pow(x,i)/fact(i));
t=t*(-1);
}
printf("\nOUTPUT:");
printf("\n******");
printf("\n COS(x) value :
%f\n",sum);
printf("\n Built in Function
for COS(x) : %f\n",cos(x));
getch();
}
fact(int n)
{
int i,f=1;
for(i=1;i<=n;i++)
f=f*i;
return(f);
}
0 comments:
Feel free to contact the admin for any suggestions and help.