Write a program which takes two integers (num1 and num2) as input from the user. The program should display all the prime numbers between num1 and num2. i) The program can use only for loops. ii) The program can use only while loops.
#include<iostream>
using namespace std;
int main(){
int upper,lower,i;
bool prime=true;
cout<<"Enter lower bound"<<endl;
cin>>lower;
cout<<"Enter upper bound"<<endl;
cin>>upper;
while(lower<upper){
prime=true;
if(lower==0){
prime=false;
}else{
for(i=2;i<=lower/2;++i){
if(lower%i==0){
prime=false;
break;
}
}
}
if(prime)
cout<<lower<<"\t";
++lower;
}
return 0;}
Comments
Leave a comment