Tuesday, September 27, 2016

Algorithm to find factorial of a given number.

Factorial of number n is defined as follow:

      n! = 1 * 2 * 3 * 4 * ....* n

Algorithm to find factorial of a given number N:

Step 1: Start
Step 2: Declare variables: N, fact,  i.
Step 3: Initialize variables
           fact = 1
           i = 1
Step 4: Read value of N from user.
Step 5: Repeat following steps until i = N
           fact =  fact * i
           i = i + 1
Step 6: Print fact variable.
Step 7: Stop




No comments:

Post a Comment