Fctorial of A Number

You might also like

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 3

Factorial of number

Ms. Saraswati R Bhusanur


Algorithm to find factorial of a number
1. Start
2. Declare variables: num, factorial
- num: the number for which factorial needs to be calculated
- factorial: variable to store the factorial result
3. Input a non-negative integer 'num' from the user
4. Set factorial to 1
5. Iterate from 1 to num:
Multiply factorial by the current iteration value
6. Display the factorial as the result
7. End
Num =4 N= 1 Fact = 1

N Fact Fact = Fact * N Is N = Num

1 1 Fact= 1 * 1 =1 Is 1 = 4 No
N=N+1= 1+1=2

2 1 Fact= 1 * 2 = 2 Is 2 = 4 No
N=N+1= 2+1=3

3 2 Fact= 2 * 3 = 6 Is 3 = 4 No
N=N+1= 3+1=4

4 6 Fact= 6 *4 = 24 Is 4 = 4 Yes
Print 24

You might also like