Program to find all prime factors of a number

In this program, we will find all the prime factors of a number.

Steps to solve the program
  1. Take a number as input through the user.
  2. Use for loop with range function to check for factors of the number.
  3. If a factor is divisible by 1 and by itself then it is a prime number.
  4. Use for loop with the range function to check whether a factor is a prime number or not.
  5. 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
				
			

find the sum of all prime numbers between 1 to n

check whether a number is an Armstrong number or not

Leave a Comment