(Computing e in c++ programming) You can approximate e by using the following series: e = 1 +1/1! +1/2! +1/3! +1/4! + ... + 1/ i! Write a program that displays the e value for i = 10000, 20000, ..., and 100000. (Hint: Since i!= i × (i − 1) × ...× 2 × 1 ,then 1/i! is 1/i(i-1)! . Initialize e and item to be 1 and keep adding a new item to e. The new item is the previous item divided by i for i = 2, 3, 4, ...)
1
Expert's answer
2012-09-06T09:35:36-0400
#include <iostream> using namespace std;
void f(long double& q) { & long double& a,s,i;
a=1; s=1;
& for ( i=1;i<q;i++){ a=a+1/s; s=s*i; }
cout.precision(15);
cout<<"e& "<<a; &
cout<<"\n\n"; & & & & }
int main() {
cout <<"for i = 10000& \n"; f(10000);
cout <<"for i = 20000& \n"; f(20000); & & cout <<"for i = 30000& \n"; f(30000);
Numbers and figures are an essential part of our world, necessary for almost everything we do every day. As important…
APPROVED BY CLIENTS
Finding a professional expert in "partial differential equations" in the advanced level is difficult.
You can find this expert in "Assignmentexpert.com" with confidence.
Exceptional experts! I appreciate your help. God bless you!
Comments
Leave a comment