.
Home About-us Privacy Policy Contact-us Services

Friday, October 9, 2015

C++ Program to check no is prime or not prime using class

ad+1

Program -


#include<iostream.h>
#include<conio.h>
class abc
{
int n;
public:
abc(int c)
{
n=c;
}
void print();
};
void abc::print()
{
int i;
if(n==1)
{
cout<<"not prime";
return;
}
for(i=2;i<=n/2;i++)
if(n%i==0)
{
cout<<"not prime";
return;
}
cout<<"number is prime";
}
void main()
{
int n;
clrscr();
cout<<"enter the number:";
cin>>n;
abc a(n);
a.print();
getch();
}

Output - 

enter the number:3
number is prime





0 comments:

Post a Comment

Home About-us Privacy Policy Contact-us Services
Copyright © 2014 All Programs Examples | All Rights Reserved. Blogger Templates Download Blogger Templates