Computer Science, asked by agrata1267, 3 months ago

Write an algorithm to find the factorial of a number taken as input from the user

The factorial of a number n is defined as

n * (n-1) * (n-2)… 3 * 2 * 1

For example factorial of 5 is

5 * 4 * 3 * 2 * 1 = 120​

Answers

Answered by MrBasic
1

Algorithm to calculate factorial

1. Read 'n' as a positive integer

2. If n = 0 print 1

Else

3. Assign an integer value variable (factorial = n)

4. n = n - 1

5. factorial = factorial * n

6. if n > 1 go to step 4

Else

7. print factorial

Answered by divyanshgshah
0

Answer:

1) start

2) Input a number 'n' (positive integer)  from user

3)If n is equal to 0

then , print 1

Else,

4) Assign  a integer value variable  (factorial = n )

5)n=n-1

6)If n >1 , then loop statement 4

Else,

7)Print program or factorial

8)End

Explanation:

Underlined statement is to indicate that we are using if then else statement in statement 3 and 4 ,  else statement in statement 6 and 7 .

It is necessary to write start and stop / end in starting and ending of program respectively .

Hope it helps you …..

Similar questions