answer question 31 from the picture, write the code in c++ language 346 I Chapte
ID: 3585857 • Letter: A
Question
answer question 31 from the picture, write the code in c++ language
346 I Chapter 5: Control Structures II (Repetition amount accumulated when the interest is compounded continuously It also appears in problems relating to exponential growth and decay. It a program that computes the value m .(1 )" between certain values of n and then with e. For example, you can compute the values nown that e is an irrational number. The value of e to nine decimal places is e = 2.718281827. Write of the expression li compare the values of the expression between 100 and 10,000 with an increment of 100, or between 1,000 and 1,000,000 with an increment of 1,000. Exercise 30 defines the number e. The value of e can be approximated using the following expression: 31. 2! 3! n! where n is a positive integer. Write a program that uses this formula to approximate the value of e. Test your program for n 4, 8, 10, and 12. Exercise 30 defines the number e and Exercise 31 shows how to approximate the value of e using a different expression. Interestingly, the value ofe can also be approximated using the following expression: 32. 2+ 2 3+3 4 +4 (n -1) ntn Write a program that uses this formula to approximate the value of e. Test your program for n3,5, 10, 50, and 100. Bianca is preparing special dishes for her daughter's birthday. It takes her a minutes to prepare the first dish, and each following dish takes b minutes longer than the previous dish. She has t minutes to prepare the dishes. For example, if the first dish takes a 10 minutes and b then the second dish will take 15 minutes, the third dish will take 20 minutes, and so on. If she has 80 minutes to prepare the dishes, then she can prepare four dishes because 10+15+ 20 25 70. Write a program that prompts the user to enter the values of a, b, and t, and outputs the number of dishes Bianca can prepare. 33. 7473-9Explanation / Answer
#include<iostream>
using namespace std;
// funcition that returns factorial of a number
int fact(int n)
{
if(n==1)
return 1;
else
return n*fact(n-1);
}
// this is the function that takes n and returns value of e
double eval(int n)
{
double sum = 2;
for(int i=2;i<=n;i++)
{
sum = sum + (1.0f/fact(i));
}
return sum;
}
main()
{
// DRIVER
printf("n = 4 then e = %.8lf ",eval(4));
printf("n = 8 then e = %.8lf ",eval(8));
printf("n = 10 then e = %.8lf ",eval(10));
printf("n = 12 then e = %.8lf ",eval(12));
}
/*SAMPLE OUTPUT
n = 4 then e = 2.70833334
n = 8 then e = 2.71827878
n = 10 then e = 2.71828181
n = 12 then e = 2.71828183
*/
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.