Algorithm for Finding Factorial of a Number


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

Pseudocode and Algorithm for Finding Factorial of a Number

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


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

Don't Understand Algorithm and Flowchart? Learn quickly using our Expert's Notes

Want to get in-depth understanding of Algorithms?

Are You Good enough in Algorithms? Test it now?


1 comment
  • Prashanth

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

Recommended Deals End in

Java Interview Questions For Beginner Notes
Quiz for Learners
Online Games
Play 2048 Game Online and Relax.
Play 2048 Game Online

Search Tags

    Pseudocode for Finding Factorial of a Number

    Factorial of a Number Algorithm

    Find a factorial of a number Pseudocode

    Simple code to find factorial of a number