C++ program to check whether the number is prime or not
#include<iostream.h>
#include<conio.h>
class prime
{
int num,i,p;
public:
void input()
{
cout<<"Enter any number\n";
cin>>num;
}
void output()
{
if(num==1 || num==2)
cout<<"Number is prime";
else
{
for(i=2;i<num;i++)
{
if(num%i==0)
{
cout<<"Number is not prime";
break;
}
else
p++;
if(i==num-1)
{
if (p!=0)
cout<<"Number is prime";
}
}
}
}
};
void main()
{
clrscr();
prime a;
a.input();
a.output();
getch();
}
No comments:
Post a Comment