Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
15 views

Prime Numbers in A Range

The code takes in two numbers as input, checks if the lower number is less than 2, and if not prints out all the prime numbers between the two input numbers.

Uploaded by

Shriram Arvinth
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

Prime Numbers in A Range

The code takes in two numbers as input, checks if the lower number is less than 2, and if not prints out all the prime numbers between the two input numbers.

Uploaded by

Shriram Arvinth
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

#include <iostream>

using namespace std;

int main()
{
int a,b;
cin >> a >> b;
if(a < 2)
{
cout << "Invalid Lower Range";
}
else
{
cout << "Prime Numbers between "<< a << " and "<< b << ":" <<endl;
int i=a;
int x=2;
while(i<=b)
{
if(i==2)
{
printf("2");
}
while(x<i)
{
if(i%x==0)
{
break;
}
else if(x==(i-1))
{
cout << i <<" ";
}
x++;
}
x=2;
i++;
}
}
return 0;
}

You might also like