- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

When it is required to find the smallest divisor of a an integer, a simple ‘for’ loop is used.

Below is a demonstration of the same −

first_num = int(input("Enter a number...")) my_list = [] print("The number is ") print(first_num) for i in range(2,first_num+1): if(first_num%i==0): my_list.append(i) my_list.sort() print("The smallest divisor is : ") print(my_list[0])

Enter a number...56 The number is 56 The smallest divisor is : 2

The number is taken as an input from the user.

An empty list is defined.

The number taken from user is displayed on the console.

The number range is iterated over.

It is checked to see if the number divided by the iterator is 0.

If yes, it is appended to the empty list.

In the end, this list is sorted.

The first element of the sorted list is displayed on the console, since this is the smallest divisor.

- Related Questions & Answers
- Golang Program to Find the Smallest Divisor of an Integer
- Find the Smallest Divisor Given a Threshold in C++
- Python program to find better divisor of a number
- Find an integer X which is divisor of all except exactly one element in an array in Python
- Find the k-th smallest divisor of a natural number N in C++
- Program to find out the sum of the number of divisor of the divisors in Python
- Find an integer X which is divisor of all except exactly one element in an array in C++
- Java program to find the smallest number in an array
- C# Program to find the smallest element from an array
- Python program to find the sum of all even and odd digits of an integer list
- Python program to find the smallest number in a list
- Java program to find the 2nd smallest number in an array
- 8085 Program to find the smallest number
- Program to find kth smallest n length lexicographically smallest string in python
- Java program to find Largest, Smallest, Second Largest, Second Smallest in an array

Advertisements