Question: Problem 7 Write a program to find the factorial of an integer n, defined as n ! = n (n-1) (n-2) (n-3) .. (2) (1)

Problem 7

Write a program to find the factorial of an integer n, defined as

n ! = n (n-1) (n-2) (n-3) .. (2) (1) (n = 1, 2, 3, .)

Also, 0! = 1

The program should prompt you for the input n and Use a for loop to do the repeated multiplication. The program should also work for n=0.

Include an error-check to reject negative values of n.

Format the result so that the value of n! displays all the integer digits. Otherwise you will see round-off when n gets large enough.

Show the result for several values of n (including n=0), and compare to MATLABs built-in function factorial(n).

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!