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 are the desirable attributes for memory managment?

0 Answers  


What is polymorphism in oop example?

0 Answers  


What is the difference between pass by reference and pass by value?

12 Answers   Pfizer, TCS,


when to use 'mutable' keyword and when to use 'const cast' in c++

0 Answers   TCS,


What is encapsulation c#?

0 Answers  






What are the 5 oop principles?

0 Answers  


write a program to find 2^n+1 ?

0 Answers   CTS,


Can we override main method?

0 Answers  


What polymorphism means?

0 Answers  


What is a friend function & its advantage?

2 Answers   TCS,


Explain the advantages of inheritance.

0 Answers   TCS,


Out of 4 concepts, which 3 C++ Follow?

1 Answers   TCS,


Categories