write a progra in c++ using class & object to find out
wheather a given no. is prim or not.
Answer Posted / ***..$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 |
Post New Answer View All Answers
Can we have inheritance without polymorphism?
what are the different types of qualifier in java?
can inline function declare in private part of class?
What is the difference between procedural programming and oops?
Which is better struts or spring?
What is abstraction with example?
What is abstraction in oop with example?
What is class and object with example?
What is the real life example of polymorphism?
Is oop better than procedural?
What is oops and its features?
Why do while loop is used?
hi, this is raju,iam studying b.tech 2nd year,iam want know about group1 and group2 details, and we can studying without going to any instutions? please help me.
INSTANCE FIELDS DECLARED private ARE ACCESSIBLE BY THE METHODS ONLY.CAN WE CHANGE THE private FIELD OF AN OBJECT IN A METHOD OF SOME OTHER OBJECT OF THE SAME CLASS?
c++ program to swap the objects of two different classes