Use app×
Join Bloom Tuition
One on One Online Tuition
JEE MAIN 2025 Foundation Course
NEET 2025 Foundation Course
CLASS 12 FOUNDATION COURSE
CLASS 10 FOUNDATION COURSE
CLASS 9 FOUNDATION COURSE
CLASS 8 FOUNDATION COURSE
0 votes
986 views
in Computer by (51.9k points)
closed by

Program to find the factors of a whole number using while loop.

2 Answers

+1 vote
by (49.5k points)
selected by
 
Best answer
#Find the factors of a number using while loop 

num = int(input("Enter a number to find its factor: ")) 

print (1, end=' ') #1 is a factor of every number 

factor = 2 

while factor <= num/2 : 

if num % factor == 0: 

#the optional parameter end of print function specifies the delimeter 

#blank space(' ') to print next value on same line 

print(factor, end=' ') 

factor += 1 

print (num, end=' ') #every number is a factor of itself 

Output: 

Enter a number to find its factors : 6 

1 2 3 6
+1 vote
by (45 points)

write a  program to find factors of a number using while loop. Here is its answer:

print("Enter the Number: ")
num = input()

num = int(num)
print("\nFactors of", num)

i = 1
while i<=num:
    if num%i==0:
        print(i)
    i = i+1

Welcome to Sarthaks eConnect: A unique platform where students can interact with teachers/experts/students to get solutions to their queries. Students (upto class 10+2) preparing for All Government Exams, CBSE Board Exam, ICSE Board Exam, State Board Exam, JEE (Mains+Advance) and NEET can ask questions from any subject and get quick answers by subject teachers/ experts/mentors/students.

Categories

...