Question
The problem is: Interestingly, the value of e can also be approximated using the following expression: 2+1/(1+1/(2+2/(3+3/(4+4/(5+5/(n+n)))))) Write a program that uses this formula to
The problem is: "Interestingly, the value of e can also be approximated using the following expression:
2+1/(1+1/(2+2/(3+3/(4+4/(5+5/(n+n))))))
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. Use setprecision(15) to format the output for the tests.
Test your program for n = 3, 5, 10, 50, and 100."
I can get the answer for when n=3 that is rounded (aka e=3 not 2.700000000000), but I do not know how to loop these values or proceed forth in increments.
1 #include 2 #include 3 using namespace std; 4 5 int main() 6 { 7 int n; 8 int value; 9 int x = 0; 10 int t = 3; 11 int factorial; 12 cout < < fixed < < showpoint < < setprecision (15); 13 cout < < "Please input the value of n: "; 14 cin>>n; 15 while (n >= t) 16 { 17 18 8227222227828 19 20 21 23 24 25 26 29 if ((n = t)) (factorial t+t; x = 1 / (1+1/(2+2/(factorial))); value = 2 + x; cout < < t; break; } else if ((n> t)) {t = 5; factorial += (t+t); x = 1 / (1+1/(2+2/ (3+3/(4+4/ (factorial))))); value = 2 + x; t++; } else {cout < < "Nothing.";} 30 31 } 32 cout < < "This is the value of e: < < value; 33 return 0; 34 } 11 Edit & Run
Step by Step Solution
3.50 Rating (160 Votes )
There are 3 Steps involved in it
Step: 1
exercise has nothing whatsoever to do with factorials 1 include 2 include The 3 using na...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Document Format ( 2 attachments)
635e2ab04e29b_182017.pdf
180 KBs PDF File
635e2ab04e29b_182017.docx
120 KBs Word File
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started