The factorial of a non-negative integer n, denoted by n!, is the product of all positive integers less than or equal to n. For example,
5! = 5 x 4 x 3 x 2 x 1 = 120
Here are the steps to calculate the factorial of a number:
- Decide on the value of n for which you want to calculate the factorial.
- Create a variable (e.g. “factorial”) and set its initial value to 1.
- Create a loop that iterates from 1 to n.
- Within the loop, multiply the value of “factorial” by the current loop iteration value.
- After the loop is completed, the value of “factorial” is the factorial of n.