April 13, 2024
c-program c ++

Program to Show Prime Numbers between Range

This article shows how to write a C or C++ program to show prime numbers between a Range. Before start let us discuss about the prime numbers.

What is Prime Number?
In mathematics Prime Number are those number whose can be divided evenly only by 1, or itself. It must be a whole number greater than 1. For example: 5 can only be divided evenly by 1 or 5, so it is a prime number. 6 can be divided evenly by 1, 2, 3 and 6. So 6 is not a prime number. it is a composite number.

The first few prime numbers are 2, 3, 5, 7, 11, 13, 17, 19, 23. There is no largest prime number. For every prime number p there exists a prime number p’ such that p’ is greater than p. This number was demonstrated in ancient times by the Greek mathematician Euclid.

Program to Show Prime Numbers between Range
int main(){
int i,j,n,f,k=0;     cout<<”      ” This program will show Prime numbers between a range. “”<<endl<<endl;

cout<<“How many numbers ? Give a integer number.”<<endl;

if(n<0) {
cout<<“Negative number not allow,Please give a positive number.”<<endl<<endl;
goto xx;

cout<<“Prime numbers between 1 to “<<n<<” are :”<<endl;

for(i=1;i<=n;i++) {
if ((i%j)==0) f=1;
if (f==0) {
cout<<i<<”  “;

if (k==0) {


Rashedul Alam

I am a software engineer/architect, technology enthusiast, technology coach, blogger, travel photographer. I like to share my knowledge and technical stuff with others.

View all posts by Rashedul Alam →

One thought on “Program to Show Prime Numbers between Range

Leave a Reply

Your email address will not be published. Required fields are marked *