How to construct a program that will be able to excute this
How to construct a program that will be able to excute this function e^x = 1+ x + x^2/2! + x^3/3! + x^4/4! + ....... On c++. The ! means factorial. http://people.math.sc.edu/girardi/m142/handouts/10sTaylorPolySeries.pdf
Solution
Solution:
#include <iostream>
using namespace std;
double factorial(double num) //this function calculates the factorial of number
{
double fact;
fact=1.00;
while(num>0)
{
fact=fact*num;
num=num-1;
}
return (fact);
}
double pow(double a, double b) // this function calculates the power of number
{
double power;
power=a;
double n;
n=1;
while(n<b)
{
power=power*a;
n=n+1;
}
return power;
}
int main()
{
double ex,x;
double power;
double n;
cout<<\"Please enter the value of x: \";
cin>>x;
cout<<\"Enter the number of terms that u want to calculate this formula to(number of terms=power): \";
cin>>power;
n=1;
ex=1;
while(n<=power)
{
ex=ex+(pow(x,n)/factorial(n));
n=n+1;
}
cout<<\"Output is: \"<<ex<<\'\ \';
return 0;
}
