write a progra in c++ using class & object to find out
wheather a given no. is prim or not.

Answers were Sorted based on User's Feedback



write a progra in c++ using class & object to find out wheather a given no. is prim or not. ..

Answer / ***..$indhu..***

#include<iostream.h>
#include<conio.h>
class prime
{
int n,i;
public:
void giveno(int);
void no_prime();
};
void prime::giveno(int a)
{
n=a;
}
void prime::no_prime()
{
i=2;
if(i<=n-1)
{
if(n%i==0)
{
cout<<endl<<"not prime no";
else
cout<<endl<<"prime no";
break;
}
if(n==i)
{
cout<<endl<<"prime no";
}
}
}
int main()
{
prime p1;
p1.giveno(5);
p1.no_prime();
return 0;
}

Is This Answer Correct ?    33 Yes 10 No

write a progra in c++ using class & object to find out wheather a given no. is prim or not. ..

Answer / rakesh ranjan

#include<conio.h>
void main()
{
int a,i;
printf("enter the number ");
scanf("%d",&a);
for(i=2;i<a;i++)
if(a%i==0)
{
printf("number is not Prime");
break;
}
if(i==a)
printf("Prime number");
getch();
}

Is This Answer Correct ?    16 Yes 6 No

Post New Answer

More OOPS Interview Questions

What is the use of fflush(stdin) in c++?

4 Answers   HCL,


What is new keyword in oops?

0 Answers  


How do you achieve polymorphism?

0 Answers  


Round up a Decimal number in c++.. example Note = 3.5 is as 4 3.3 is as 3

3 Answers   Accenture, Cognizant, IBM,


Following are the class specifications: class {int a}; class {int b}; Using friend funtion,calculate the max of two objects and display it.

0 Answers  






Can anyone please explain runtime polymorphism with a real time example??at what ciscumstances we go for it??

1 Answers  


How to Increment the value of the empid E001 for each and every employee by using the programe?

1 Answers   Accenture,


c++ provides classes...and classes do what we want but why then strcut are used...if we say data hiding... it is also provided by c++ in structs then why to prefer clasess

1 Answers   HCL, TCS,


Write a program to multiply 3x3 matrics

1 Answers  


Is oop better than procedural?

0 Answers  


what is mean by design pattern

4 Answers  


what is the difference between inter class and abstract class...?

0 Answers  


Categories