
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
Program to find Prime Numbers Between given Interval in C++
In this tutorial, we will be discussing a program to find prime numbers between given intervals.
For this we would be provided with two integers. Our task is to find the prime numbers in that particular range.
Example
#include <bits/stdc++.h> using namespace std; int main() { int a, b, i, j, flag; //getting lower range a = 3; //getting upper range b = 12; cout << "\nPrime numbers between " << a << " and " << b << " are: "; for (i = a; i <= b; i++) { if (i == 1 || i == 0) continue; flag = 1; for (j = 2; j <= i / 2; ++j) { if (i % j == 0) { flag = 0; break; } } if (flag == 1) cout << i << " "; } return 0; }
Output
Prime numbers between 3 and 12 are: 3 5 7 11
- Related Articles
- Python program to print all Prime numbers in an Interval
- Write a Golang program to find prime numbers in a given range
- C++ Program to Implement Wheel Sieve to Generate Prime Numbers Between Given Range
- C++ Program to Implement Segmented Sieve to Generate Prime Numbers Between Given Range
- Find two distinct prime numbers with given product in C++ Program
- Program to find sum of prime numbers between 1 to n in C++
- C++ Program to Implement Sieve of eratosthenes to Generate Prime Numbers Between Given Range
- C++ Program to Implement Sieve of Atkin to Generate Prime Numbers Between Given Range
- How to Print all Prime Numbers in an Interval using Python?
- C++ Program to Generate Prime Numbers Between a Given Range Using the Sieve of Sundaram
- C++ Program to Display Prime Numbers Between Two Intervals
- Java Program to Display Prime Numbers Between Two Intervals
- Swift program to display prime numbers between two intervals
- Program to print prime numbers in a given range using C++ STL
- C program to display the prime numbers in between two intervals

Advertisements