how to pseudocode take an integer from the user and display the factorial of the number

1 answer

1. Input a number from user and save it to variable 'num'.
2. Initialize a variable 'fact' to 1.
3. If 'num' is less than 0, display an error message and end program.
4. If 'num' is equal to 0 or 1, display 1 as the factorial of 'num' and end program.
5. Otherwise, create a loop from 'num' to 1 with a decrement of 1.
6. In each iteration of the loop, multiply 'fact' by the current value of the loop variable.
7. After the loop has finished, display 'fact' as the factorial of 'num'.
8. End program.

Pseudocode:

1. Input num
2. fact = 1
3. If num < 0, display error message and end program
4. If num = 0 or 1, display 1 as factorial of num and end program
5. For i = num to 1 with decrement of 1 do the following:
6. fact = fact * i
7. Display fact as factorial of num
8. End program