# Algorithm for Finding Factorial of a Number

[317205 views]

### What is Factorial of a number?

Product of all consecutive Integer numbers up to n is called Factorial of a Number and is denoted by n! For Example, the value of 5! is 120.

Mathematically it is written as,
n! = 1 * 2 * 3 * 4 * ... * (n-1) * n
For example, the factorial of 5 is,
5! = 1 * 2 * 3 * 4 * 5 = 120 ### Algorithm for Finding Factorial of a Number

Step 1: Start Step 2: Declare Variable n, fact, i Step 3: Read number from User Step 4: Initialize Variable fact=1 and i=1 Step 5: Repeat Until i<=number 5.1 fact=fact*i 5.2 i=i+1 Step 6: Print fact Step 7: Stop

### Pseudocode for Finding Factorial of Number

Read number Fact = 1 i = 1 WHILE i<=number Fact=Fact*i i=i+1 ENDWHILE WRITE Fact

#### Explanation

We first take input from user and store that value in variable named “n”. Then we initialize a variable “Fact” with value 1 (i.e Fact=1) and variable i with value 1(i.e i=1). Repeat next two steps until i is less than n.

1. Multiply Fact with current value of i
2. Increment i with 1
At last, print the value of Fact.

Let’s take an example,
Let the input be 5.
The equation that gets created by our algorithm is 5x4x3x2x1.
So, The Factorial of 5 is 120(5x4x3x2x1).

##### Java Program for Factorial of a Number

1 comment
• Prashanth

Super definition awesome I am intelligent so I can able to understand this concept .