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
#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;
}
Comments
Leave a comment