Tuesday, 27 November 2012

Write a program that will calculate the sum of expension of sinx in Maclaurin Series.


// x - x^3/3! + x^5/5! - x^7/7! + - - - - - - - - - - upto so on

#include <math.h> // to perform power fucntion.....
#include <iostream>
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 sin(x)."<<endl;
cout << endl;
cout << "Which is sin(x)= x - x^3/3! + x^5/5! - x^7/7! +  - - - - - - - "<<endl;
cout << endl;
cout << "Enter the Value or X: ";
cin >> x_value;
cout << "Enter Maximum Power of series: ";
cin >> max_power;
for (int i=1;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; // power fucntion
sum=sum+(term*sign);
sign*=-1;
}
cout << "Sum is: " << sum <<endl;
return 0;
}

No comments:

Post a Comment