The factorial of a positive integer n is equal to
1*2*3*...n
. You will learn to calculate the factorial of a number using for loop in this example.
The factorial of a number is the product of all the integers from
1
up to that number. The factorial can only be defined for positive integers.
The factorial of a negative number doesn't exist. And the factorial of
0 is 1
.
For example :The factorial of a positive number n
, say 5
, is denoted by 5!
and is given by :
5! = 1 * 2 * 3 * 4 * 5 = 120​
So, the Mathematical logic for factorial is :
n! = 1 * 2 * 3 * ... * n
n! = 1 if n = 0 or n = 1​
In this program, the user is asked to enter a positive integer. Then the factorial of that number is computed and displayed on the screen.
Find the Factorial of a Given Number :