December 2001
Beginner
976 pages
22h 4m
English
![]() | Applying It |
Try to complete the following exercises by yourself.
Write a program to calculate the factorial of all numbers supplied by the user. (The factorial of an integer n is the product of all numbers between 1 and n: 1*2*3*…*n). The program should work as follows:
1. |
Ask the user to enter a number n between 1 and 20, or 0 to exit the program.
|
2. |
Validate n, if 0 exit program, if invalid display error message and go back to step 1.
|
3. |
Calculate the factorial of n.
|
4. |
Display n.
|
5. |
Go back to Step 1.
|
Note that factorials grow very fast, so limit the number to 20 or less to avoid arithmetic overflow errors. You ...
Read now
Unlock full access