Algorithm for Finding Factorial of a Number

(3571 Views)


What is Factorial of a number?

Product of all consecutive Integer numbers upto n is called Factorial of a Number and is denoted by n!. For Example, the value of 5! is 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

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).

        

Solution Didn't Worked 7 DownvotesDownvote



Comments

1 comment
  • Prashanth

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



Search


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