#include<iostream.h>
#include<conio.h>
class s{
int n;
public:
void getvalues();
void evodd();
void prime();
};
void s::getvalues()
{
cout<<"Enter a number greater than 1:";
cin>>n;
}
void s::evodd()
{
if(n%2==0)
cout<<"The number is even and ";
else
cout<<"The number is odd and ";
}
void s::prime()
{
int flag=0;
for(int i=2;i<n;i++)
{
if(n%i==0)
{
flag=1;
break;
}
}
if(flag==1)
cout<<"it is not a prime number.";
else
cout<<"it is a prime number.";
getch();
}
void main()
{
clrscr();
s ob;
char c;
do{
clrscr();
ob.getvalues();
ob.evodd();
ob.prime();
cout<<"\nDo you wish to continue? (Y/N) :";
cin>>c;
}while(c=='y'||c=='Y');
getch();
}
Sunday, January 18, 2015
To check a number is even or odd or prime
Subscribe to:
Post Comments (Atom)

No comments:
Post a Comment