How do you write a c++ program to estimate e^x, s.t.?
e= x^0/0! + x^1/1! + x^2/2! + x^3/3! +...x^N/N!
you should
-show some information on the screen for asking an input x
-input x from the keyboard
-print: cout << "e^x = " << A
where A is a variable where e^x is stored.
My teacher thinks we're already programmers yet this is an intro science elective for engineers and she doesn't realize that and no one in our class is ready or have been taught the basics.
Can you help me out with the program code and explain how it works? thank you
Update:don't you have to use the syntax exp(x) which is to raise e to a certain power?
Comments
Programming for engineers. So have you had infinite series in Calculus yet? It is just a set of numeric formulae that can be used to approximate values. The more terms that are included the more accurate the resulting value. See the link below...
Are you in City college's CSC 102 by any chance?
So far this is what I have, but Visual C++ is giving me an error... & won't tell me what it is!
# include <iostream>
# include <cmath>
using namespace std;
int main ()
{
double A;
int x;
cout << "Please input a value for x"<<endl;
cin >> x;
A = (pow (x, 0.0)/1)+ (pow (x, 1.0)/1)+ (pow (x,2.0)/2)+ (pow (x,3.0)/6)+ (pow (x,4.0)/24)+ (pow(x,5.0)/120);
cout << "e=" << A <<endl;
return 0;
}