All prime number in any range in C++ by R4R Team


program:

#include < iostream>
using namespace std;
class myclass
{
public:
int prime(int n)
{
int i;
for(i=2;i {
if(n%i==0){
return 0;
}
}
return 1;
}
};
int main()
{
int x,y,i;
myclass obj;
cout<<"Enter rangen";
cin>>x>>y;
cout<<"All Prime number in this range is:"<< endl;
for(i=x;i<=y;i++)
if(obj.prime(i))
cout<< i<<" ";
return 0;
}


output-

Enter range
13 30
All Prime number in this range is:
13 17 19 23 29




Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!