Chapter 4: Problem 34
(Factorial) The factorial of a nonnegative integer \(n\) is written \(n !\) (pronounced "n factorial") and is defined as follows: \(n !=n \cdot(n-1) \cdot(n-2) \cdot \ldots \cdot 1 \quad(\text { for values of } n \text { greater than } 1)\) and \\[ n !=1 \quad(\text { for } n=0 \text { or } n=1) \\] For example, \(5 !=5 \cdot 4 \cdot 3 \cdot 2 \cdot 1,\) which is \(120 .\) Use while statements in each of the following: a) Write a program that reads a nonnegative integer and computes and prints its factorial. b) Write a program that estimates the value of the mathematical constant \(e\) by using the formula: \\[ e=1+\frac{1}{1 !}+\frac{1}{2 !}+\frac{1}{3 !}+\ldots \\] Prompt the user for the desired accuracy of \(e\) (i.e., the number of terms in the summation) c) Write a program that computes the value of \(e^{x}\) by using the formula \\[ e^{x}=1+\frac{x}{1 !}+\frac{x^{2}}{2 !}+\frac{x^{3}}{3 !}+\ldots \\] Prompt the user for the desired accuracy of \(e\) (i.e., the number of terms in the summation).
Short Answer
Step by step solution
Key Concepts
These are the key concepts you need to understand to accurately answer the question.