Interview Questions   Tutorials   Discussions   Programs   Videos   

C++ - Write a program in c++ using class & object to find out wheather a given number is primary or not.




1153
views
asked marvit August 18, 2014 11:49 AM  

Write a program in c++ using class & object to find out wheather a given number is primary or not.


           

1 Answers



 
answered By bhjahnavi   0  
/* program to find whether a given number is prime or not*/
#include<iostream.h>
#include<conio.h>
class prime_no

{

int n,i,f;

public:

void input();

void output();

};

void prime_no::input()

{

cout<<”Enter any number: “;

cin>>n;

}

void prime_no::output()

{

f=0;

for(i=2;i<=(n/2);i++)

{

if(n%i==0)

f=1;

}

if(f==0)

cout< ;<n<<” is a prime number”;

else

cout<<n<<” is not a prime number”;

}

void main()

{

prime_no p1;

clrscr();

p1.input();

p1.output();

getch();

} 
flag   
   add comment

Your answer

Join with account you already have

FF

Preview


Ready to start your tutorial with us? That's great! Send us an email and we will get back to you as soon as possible!

Alert