- Related Questions & Answers
- C# program to print all the numbers divisible by 3 and 5 for a given number
- Program to print all the numbers divisible by 3 and 5 in C++
- Python Program for Efficient program to print all prime factors of a given number
- Check if a large number is divisible by 2, 3 and 5 or not in C++
- Python Program for Smallest K digit number divisible by X
- Binary Prefix Divisible By 5 in Python
- Count n digit numbers divisible by given number in C++
- C Program for efficiently print all prime factors of a given number?
- Python Program to check whether it is possible to make a divisible by 3 number using all digits in an array
- Print all 3 digit repeating numbers in a very large number in C++
- Python Program to print all permutations of a given string
- Python program to print all even numbers in a range
- Python program to print all odd numbers in a range
- Possible to make a divisible by 3 number using all digits in an array in C++
- C++ Program for the Largest K digit number divisible by X?

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

This is a python program to print all the numbers which are divisible by 3 and 5 from a given interger N. There are numerous ways we can write this program except that we need to check if the number is fully divisble by both 3 and 5.

Below is my code to write a python program to print all the numbers divisible by 3 and 5 −

lower = int(input("Enter lower range limit:")) upper = int(input("Enter upper range limit:")) for i in range(lower, upper+1): if((i%3==0) & (i%5==0)): print(i)

Enter lower range limit:0 Enter upper range limit:99 0 15 30 45 60 75 90

Above we try to print all the numbers between 0 and 99 which are divisble by 3 and 5. Same program can be used to print all the number between 0 and 1000 which are divisible by 3 and 5, we just need to alter our range and our output will be something like,

Enter lower range limit:0 Enter upper range limit:1000 0 15 30 45 60 75 90 105 120 135 150 165 180 195 .... .... 915 930 945 960 975 990

In case we want to write a program which will print all the numbers in a range divisible by a given number not the fixed number like above, i just need to update by program like,

#Incase we want to print all number between a range divided by any given number n = int(input("Enter the number to be divided by:")) for i in range(lower, upper+1): if(i%n==0): print(i)

Below the steps to write above code −

Take the lower and upper limit .i.e. the range from the user.

Take the number to be divided by from the user. In case of our main problem, because we know that numbers(3 and 5), i write the 3 and 5 in the if statement only.

Using a loop with &(and) operator statement(so that it print only those numbers which are divisble by both 3 & 5), prints all the factors which is divisible by the number.

Exit.

Advertisements