Question: 3 . The factorial of a non - negative integer x , expressed as x ! , refers to x multiplied by the product of

3. The factorial of a non-negative integer x, expressed as x!, refers to x multiplied by the
product of all integers less than x, down to 1.
Formally, it is written like this:
x factorial= x!= x (x 1)(x 2)...1
Note that there is a special case of zero factorial, which is always 1. That is:
0!=1
For example, to work out 3 factorial, you compute the following:
321=6
To work out 7 factorial, you compute the following:7654321=5040
Write a function containing a loop that computes and stores as a new object the factorial of any
non-negative integer mynum by decrementing mynum by 1 at each repetition of the braced
code. Return an object containing the factorial of mynum (mynum_fac), and show the contents
of mynum_fac outside the main function.
Using your function, compute the factorial:
a. mynum=5
b. mynum=14
c. mynum =-1

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 Programming Questions!