Header Ads

Print All Prime Number in a Between Two Number Intervals Using While Loop in C++

C++ Program to Print All Prime Number in a Given Range Using While Loop 



Example: Code Program

#include<iostream>
using namespace std;
main(){
int l,h,i,j,f= -1;
cout<<"Find the Prime Number in a Given Range:"<<endl;
cout<<"-----------------------------------------"<<endl;
cout<<"Enter The Starting Range (Not 1 or Negative Value):";
cin>>l;
cout<<"Enter The Ending Range:";
cin>>h;
while(l<=h){
f = -1;
j = 2;
while(j<=l/2){
if(l%j==0)
f++;
j++;

}
   if(f == -1)
cout<<l<<"\t";
l++;

}

}

Output:



No comments

Powered by Blogger.