Write a pseudo-code to calculate the factorial of a given number
Answers
Answered by
45
- Question⇒ Write a pseudo-code to calculate the factorial of a given number?
Step-by-step explanation:
- Pseudocode for Factorial of a number :
- Step 1: Declare N and F as integer variable.
- Step 2: Initialize F=1.
- Step 2: Enter the value of N.
- Step 3: Check whether N>0, if not then F=1.
- Step 4: If yes then, F=F*N
- Step 5: Decrease the value of N by 1 .
- Step 6: Repeat step 4 and 5 until N=0.
- Step 7: Now print the value of F.
- The value of F will be the factorial of N(number).
Answered by
8
The required solution to calculate the factorial of a given number is given below:
- Step 1: Declaring a number N and for a factorial fact and both are integer variables.
- Step 2: Initialize the variable fact to 1.
- Step 3: A value is taken for N from the user.
- Step 4: A condition is checked if N>0 and if the condition is not true then fact= 1.
- Step 5: If the above condition is true, then fact=fact*N.
- Step 6: The value of N is decreased by 1.
- Step 7: Step 4 and Step 5 are repeated until the value N becomes 0.
- Step 8: The value of the fact is printed.
The factorial of the given number N is stored in fact.
Similar questions