In mathematics, a factorial of a number is calculated by multiplying that number by all of the successive values less than it, stopping at 1. For example, factorial of 4 is written 4! and calculated as: 4! = 4 * 3 * 2 * 1 = 24 Write a program consisting of two functions (plus the main function). The first function should read in a number and then return this value back to the main function. This value should then be passed as a parameter (by value) into the second function which calculates and displays the factorial. Note: validate the input value (in the first function) to be greater than 1. Improve your program from question 3, by changing the second function (that calculates the factorial) so that the result is returned to the main function instead of being printed where it is calculated. A new display function should be created and called from the main function that displays the calculated value.
In mathematics, a factorial of a number is calculated by multiplying that number by all of the successive values less than it, stopping at 1. For example, factorial of 4 is written 4! and calculated as:
4! = 4 * 3 * 2 * 1 = 24
Write a
Improve your program from question 3, by changing the second function (that calculates the factorial) so that the result is returned to the main function instead of being printed where it is calculated. A new display function should be created and called from the main function that displays the calculated value.
Step by step
Solved in 3 steps with 6 images