The factorial of a positive integer n, denoted by n!, is the product of all positive integers less than or equal to
n. Write a program that computes the sequence of factorial values: 1! = 1, 2! = 2, 3! = 6, 4! = 24, 5! = 120,
6! = 720, ....
(1) Use a short variable to store the value of the factorial. What is the largest value of n for which the program
correctly calculates the factorial of n?
(2) Repeat part (1), using an int variable.
(3) Repeat part (1), using a long variable.
(4) Repeat part (1), using a long long variable.
uploaded program must have four loops, each calculating sequential factorial values until a value is calculated
incorrectly.
Start by printing individual factorial values calculated by each iteration of each loop first. Observe the first
incorrect factorial value, and find a way to stop each loop's iterations at that point. (Your knowledge of integer
type ranges will help you verify that you are stopping each calculation at the right point.)
When you are satisfied that each loop operates and stops correctly, comment out (but do not remove) code
that prints individual factorial values. Your program must print just the four values of n. (Be careful to print n
for which n! is correct, and not n + 1 for which (n + 1)! is incorrect.)