In this program, we will find all the prime factors of a number.
Steps to solve the program
- Take a number as input through the user.
- Use for loop with range function to check for factors of the number.
- If a factor is divisible by 1 and by itself then it is a prime number.
- Use for loop with the range function to check whether a factor is a prime number or not.
- Print the output.
n=int(input("Enter an integer:"))
print("Factors are:")
for i in range(1,n+1):
if n%i == 0:
count = 0
for j in range(1,i+1):
if i%j == 0:
count += 1
if count == 2:
print(i,end=" ")
Output :
Enter an integer:22
Factors are:
2 11