- 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 print all the elements which can’t be divided by 2 or 3 and lie between 1 and 50, the constraints are mentioned in the form of a ‘while’ loop and ‘if’ condition.

Below is a demonstration of the same −

print("Integers not divisible by 2 and 3, that lie between 1 and 50 are : ") n = 1 while n <= 51: if n % 2 != 0 and n % 3 != 0: print(n) n = n+1

Integers not divisible by 2 and 3, that lie between 1 and 50 are : 1 5 7 11 13 17 19 23 25 29 31 35 37 41 43 47 49

The value of n is assigned to 1.

A while loop runs until this ‘n’ is not greater than 51,

It checks to see if the number is divisible by 2 or 3 or not.

If it is not divisible, the number is displayed on the console.

After every display, it is incremented.

- Related Questions & Answers
- Golang Program to print all integers between a range that aren't divisible by either 2 or 3
- Program to print all the numbers divisible by 3 and 5 in C++
- Python program to print all the numbers divisible by 3 and 5 for a given number
- Check if a large number is divisible by 2, 3 and 5 or not in C++
- Python program to print all Happy numbers between 1 and 100
- C# program to print all the numbers divisible by 3 and 5 for a given number
- Program to check if array pairs are divisible by k or not using Python
- Sum of the series 1 + (1+2) + (1+2+3) + (1+2+3+4) + ... + (1+2+3+4+...+n) in C++
- Differences between Python 2.x and Python 3.x?
- Python program to print all Disarium numbers between 1 to 100
- Program to find sum of series 1 + 2 + 2 + 3 + 3 + 3 + .. + n in C++
- Print 1 2 3 infinitely using threads in C
- C++ program to find the sum of the series 1 + 1/2^2 + 1/3^3 + …..+ 1/n^n
- Sum of the series 1 / 1 + (1 + 2) / (1 * 2) + (1 + 2 + 3) / (1 * 2 * 3) + … + upto n terms in C++
- What are the differences in between python 2.x and python 3.x versions?

Advertisements