Answer to Question #154854 in C++ for zain ul abdeen

Question #154854

 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.


1
Expert's answer
2021-01-12T11:07:45-0500




#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;}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog