Cosine series program using c
Cosine series program
#include<stdio.h
#include<conio.h>
#include<math.h>
void main()
{
int i,n,f=1,sin=-1;
float x,t,s=1;
clrscr();
printf("Enter the number of terms:");
scanf("%d",&n);
printf("Enter the value of x:");
scanf("%f",&x);
for(i=2;i<n;i=i+2)
{
f=f*i*(i-1);
t=pow(x,i);
s=s+(sin*t)/f;
sin=sin*(-1);
}
pritnf("cosine series:%f",s);
getch();
}
Enter the value of x:6
cosine series:-17.000000
#include<stdio.h
#include<conio.h>
#include<math.h>
void main()
{
int i,n,f=1,sin=-1;
float x,t,s=1;
clrscr();
printf("Enter the number of terms:");
scanf("%d",&n);
printf("Enter the value of x:");
scanf("%f",&x);
for(i=2;i<n;i=i+2)
{
f=f*i*(i-1);
t=pow(x,i);
s=s+(sin*t)/f;
sin=sin*(-1);
}
pritnf("cosine series:%f",s);
getch();
}
Output
Enter the number of terms:2Enter the value of x:6
cosine series:-17.000000
No comments: