Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Exercise 30 (Chapter 5) defines the number e and Exercise 31 (Chapter 5) shows h

ID: 3591572 • Letter: E

Question

Exercise 30 (Chapter 5) defines the number e and Exercise 31 (Chapter 5) shows how to approximate the value of e using a different expression.

Interestingly, the value of e can also be approximated using the following expression:

Write a program that uses this formula to approximate the value of e.

The program should prompt the user to input a value for n and then output the approximate value of e.

Test your program for n = 3, 5, 10, 50, and 100.

This is for a standard C++ program on cengage mindtap... I am completely lost!

1 2 + 2 1 + 1 3 + 3 4 +4 5 +5 (n-1) n-1 nt n

Explanation / Answer

#include <iostream>

using namespace std;

// utility method for evaluating e value

double eValueUtil(int start, int n) {

// terminating recursion

if(start == n-1) {

return ((n-1) + (double)(n-1)/(2*n));

}

// else add this value and call next iteration

return start + start/eValueUtil(start + 1, n);

}

// evalue of n iterations

void eValue(int n) {

// using utility function

double val = 2 + 1/eValueUtil(1, n);

cout << "e(" << n << ") is " << val << endl;

}

int main() {

int n;

cout << "Enter value of n: ";

cin >> n;

eValue(n);

}

============

Output: