/* SUMMATION OF COSINE SERIES */
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int x,n,t=-1,i,j;
double num,sum=1.0,r;
long int deno;
clrscr();
printf("\n\t\tINPUT:");
printf("\n\t\t------");
printf("\n\t\tEnter the value for x: ");
scanf("%d",&x);
printf("\n\t\tEnter the value for n: ");
scanf("%d",&n);
printf("\n\t\tOUTPUT:");
printf("\n\t\t-------");
r=x*(3.14/180.0);
printf("\n\t\tThe radius value for the given x value
is: %lf",r);
for(i=2;i<=n;i+=2)
{
num=1.0;
deno=1;
for(j=2;j<=i;j++)
{
num=num*r;
deno=deno*j;
}
sum=sum+num/deno*t;
t=t*-1;
}
printf("\n\t\tThe value for cos %d is: %lf",x,sum);
printf("\n\t\tThe built-in value for given value is:
%lf",cos(r));
getch();
}
------
Enter the value for x: 60
Enter the value for n: 4
OUTPUT:
-------
The radius value for the given x value is: 1.046667
The value for cos 60 is: 0.524443
The built-in value for given value is: 0.500460
No comments:
Post a Comment