This is a Python Program to find the factorial of a number without using recursion.
The program takes a number and finds the factorial of that number without using recursion.
1. Take a number from the user.
2. Initialize a factorial variable to 1.
3. Use a while loop to multiply the number to the factorial variable and then decrement the number.
4. Continue this till the value of the number is greater than 0.
5. Print the factorial of the number.
6. Exit.
Here is source code of the Python Program to find the factorial of a number without using recursion. The program output is also shown below.
n=int(input("Enter number:")) fact=1 while(n>0): fact=fact*n n=n-1 print("Factorial of the number is: ") print(fact)
1. User must enter a number.
2. A factorial variable is initialized to 1.
3. A while loop is used to multiply the number to the factorial variable and then the number is decremented each time.
4. This continues till the value of the number is greater than 0.
5. The factorial of the number is printed.
Case 1: Enter number:5 Factorial of the number is: 120 Case 2: Enter number:4 Factorial of the number is: 24
Sanfoundry Global Education & Learning Series – Python Programs.
To practice all Python programs, here is complete set of 150+ Python Problems and Solutions.
- Apply for Programming Internship
- Check Python Books
- Practice Programming MCQs
- Check Information Technology Books
- Apply for Python Internship