- 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 prime numbers within a given range of numbers, the range is entered and it is iterated over. The ‘%’ modulus operator is used to find the prime numbers.

Below is a demonstration of the same

lower_range = 670 upper_range = 699 print("The lower and upper range are :") print(lower_range, upper_range) print("The prime numbers between", lower_range, "and", upper_range, "are:") for num in range(lower_range, upper_range + 1): if num > 1: for i in range(2, num): if (num % i) == 0: break else: print(num)

The lower and upper range are : 670 699 The prime numbers between 670 and 699 are: 673 677 683 691

The upper range and lower range values are entered and displayed on the console.

The numbers are iterated over.

It is checked to see if they are greater than 1 since 1 is neither a prime number nor a composite number.

The numbers are iterated, and ‘%’ with 2.

This way the prime number is found, and displayed on console.

Else it breaks out of the loop.

- Related Questions & Answers
- Prime numbers within a range in JavaScript
- PHP program to find the sum of odd numbers within a given range
- How to find Kaprekar numbers within a given range using Python?
- Sum of prime numbers between a range - JavaScript
- Write a Golang program to find prime numbers in a given range
- Find a range of composite numbers of given length in C++
- Finding the count of numbers divisible by a number within a range using JavaScript
- Prime numbers in a range - JavaScript
- Golang Program to Print Odd Numbers Within a Given Range
- Print prime numbers in a given range using C++ STL
- Counting prime numbers that reduce to 1 within a range using JavaScript
- Python Generate random numbers within a given range and store in a list
- C++ Program to Generate Prime Numbers Between a Given Range Using the Sieve of Sundaram
- Finding sum of all numbers within a range in JavaScript
- Summing cubes of natural numbers within a range in JavaScript

Advertisements