Answer to Question #323167 in C++ for Lexis

Question #323167

Write a program that approximate e using a loop that terminates the difference between the two successive values of e is less than 0.0000001

1
Expert's answer
2022-04-04T07:47:43-0400
#include <iostream>
#include <iomanip>
using namespace std;


int main() {
    double sum = 1;
    double a = 1;
    int i = 1;


    while (a >= 1e-7) {
        a /= i;
        sum += a;
        i++;
    }
    cout << "Approximation to e " << fixed 
         << setprecision(8) << sum << endl;
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS