Sample Program 3
|
![]() |
||||
|
Problem statement: Calculate the factorial of a given number. Solution: The factorial of a number N is defined as:
N(N-1)(N-2)………….3.2.1 By looking at the problem, we can see that there
is a repetition of multiplication of numbers. A loop is needed to write a
program to solve a factorial of a number. Let's think in terms of writing a
generic program to calculate the factorial so that we can get the factorial
of any number. We have to multiply the number with the next decremented
number until the number becomes 1. So the value of number will decrease by 1
in each repetition. Here is the flow chart for the factorial.
|
|||||
|
|
Previous |
TOC |
Next |
||