1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
|
//c++ program to compute cosine series cos(x)= 1-(x^2/2!)+(x^3/3!)-........
#include<iostream>
#include<cmath>
using namespace std;
long fact(long);
int main()
{
long a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,no;
int sign=1;
cout<<"Input the value of x"<<endl;
cin>>a;
cout<<"input the no. of terms"<<endl;
cin>>n;
a=a*(3.14)/180;
b=2;
c=1;
s=1;
for(i=2;i<=n;++i)
{
s=s+(pow(a,i)/fact(i))*sign;
sign=sign*(-1);
}
cout<<"sum of the series is"<<s;
return 0;
}
long fact(long i)
{
int j,f=1;
for(j=1;j<=i;j++)
f=f*1;
return(f);
}
|