OOPC Practical 11


Practical : 11
Subject : Object Oriented Programming with C++

Aim : C++ program to check number is prime or not

Source Code :
#include<iostream.h>
#include<conio.h>
class prime
{
public:
void getnum()
{
int n;
cout<<"\nEnter Positive integer:";
cin>>n;
}
void check()
{
int i,n,flag=0;
for(i=2;i<=n/2;i++)
{
if(n%i==0)
{
flag=1;
break;
}
}
if(flag==0)
{
cout<<"It is a Prime number";
}
else
{
cout<<"It is not a Prime number";
}
}
};
void main()
{
int j=1;
clrscr();
prime p;
do
{
p.getnum();
p.check();
j++;
} while(j<=5);
getch();
}
Output :


Pratik Boghani

Author & Editor

Life is all about the next step.

0 comments:

Post a Comment