#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
#include<math.h>
struct anynumber
{
int n;
int prime;
public :
anynumber (int any)
{
prime = 1;
n=any;
}
void isprime();
void display()
{
if (prime==0)
cout<<endl<<"Is not a prime number";
else
cout<<endl<<"Is a prime number";
}
};
void anynumber :: isprime()
{
int i;
float s;
s=sqrt(n);
for (i=2; i<=s; i++)
{
if (n%i ==0)
{
prime =0;
return;
}
}
}
main()
{
int k;
clrscr();
cout<<"Enter the number"<<endl;
cin>>k;
anynumber testno(k);
testno.isprime();
testno.display();
getch();
}
#include<conio.h>
#include<iomanip.h>
#include<math.h>
struct anynumber
{
int n;
int prime;
public :
anynumber (int any)
{
prime = 1;
n=any;
}
void isprime();
void display()
{
if (prime==0)
cout<<endl<<"Is not a prime number";
else
cout<<endl<<"Is a prime number";
}
};
void anynumber :: isprime()
{
int i;
float s;
s=sqrt(n);
for (i=2; i<=s; i++)
{
if (n%i ==0)
{
prime =0;
return;
}
}
}
main()
{
int k;
clrscr();
cout<<"Enter the number"<<endl;
cin>>k;
anynumber testno(k);
testno.isprime();
testno.display();
getch();
}
0 Comments:
Post a Comment