prime number upto 100 in C++ by R4R Team


program:

#include < iostream>
using namespace std;
class myclass
{
public:
int prime(int n)
{
int i;
for(i=2;i< n-1;i++)
{
if(n%i==0)
{
return 0;
}
}
return 1;
}
};
int main()
{
int i;
myclass obj;
cout<<"All prime number upto 100 is:"<< endl;
for(i=2;i<=100;i++)
if(obj.prime(i))
cout<< i<<" ";
return 0;
}


output-

All prime number upto 100 is:
2 3 5 7 11 13 17 19 23 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97




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!