ComputerShikshak.com

Flowchart - Factorial of a Number

Problem Statement

Draw a Flowchart to find the Factorial of a number.

Brief Description

According to the problem statement we have to draw a flowchart that will find the factorial of a given number.

Factorial of a number is obtained by multiplying all the integer values from 1 to that that number.

Also note the following two important points in order to find the factorial of a number:
(i) Factorial is not defined for the negative numbers.
(ii) Factorial of 0 is 1 i.e. 0!=1.

For example, if 5 is given as input, we will get 120 as output since 5!=1*2*3*4*5=120.

Flowchart

Explanation

In order to draw the flowchart given above the following steps are taken into consideration:
  • Initially 1 is stored in a variable namely fact.
  • After that a number is taken as input from the user and is stored in a variable namely num.
  • If the given number is negative, the message “Factorial is not defined for the negative numbers” is displayed as output.
  • If the given number is greater than or equal to zero, factorial is computed and displayed as per the steps given below:
    • At first 1 is stored in i.
    • After that it is checked to see whether the value of i is <= the value of num. If it is then the following two steps are repeated till the value of i is <= the value of num:
      • The value of fact is multiplied with the value of i and the result is stored in the same variable i.e. fact.
      • The value of i is incremented by 1.
    • If the value of i is > the value of num then the value of fact (which contains the factorial of the value stored in num) is displayed as output.
Share this page on
Scroll to Top