prime function 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){
cout<<"It's Not Prime";
return 0;
}
}
cout<<"It's Prime";
}
};
int main()
{
int n,ans;
myclass obj;
cout<<"Enter any numbern";
cin>>n;
ans=obj.prime(n);
return 0;
}


output-

Enter any number
13
It's Prime

Enter any number
12
It's not Prime




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!