// 1 - x^2/2! + x^4/4! - x^6/6! + - - - - - - - - - - upto so on
#include <iostream>
#include <math.h> // for power fucntion
using namespace std;
int main()
{
double x_value,fact=1.0,term,sum=0,max_power;
int sign=1;
cout << "Welcome to The WORLD OF C++ PROGRAMING"<<endl;
cout << endl;
cout << "This Program will generate the Maclauren Series of cos(x)."<<endl;
cout << endl;
cout << "Which is cos(x)= 1 - x^2/2! + x^4/4! - x^6/6! + - - - - - - - "<<endl;
cout << endl;
cout << "Enter the Value or X: ";
cin >> x_value;
cout << "Enter Maximum Power of series: ";
cin >> max_power;
for (int i=0;i<=max_power;i=i+2)
{
fact=1;
for(int j=1;j<=i;j=j+1)
{
fact=fact*j;
}
term=pow(x_value,i)/fact; // usage of power fucntion
sum=sum+(term*sign);
sign*=-1;
}
cout << "Sum is of Series is: " << sum <<endl;
return 0;
}
No comments:
Post a Comment