Answer Posted / garima gupta
#include<iostream.h>
#include<conio.h>
#include<math.h>
class prime
{
private:
int i,j,j;
public:
void readn();
void display();
};
void prime::readn()
{
clrscr();
cout<<"enter no. of prime nos you want to display:"<<endl;
cin>>n;
}
void prime::display()
{
int flag;
for(i=2;i<n;i++)
{
flag=0;
for(j=2;j<=sqrt(i);j++)
{
if(i%j==0)
{
flag=1;break;
}
else(flag==0)
{
cout<<i<<" ";
}
}
}
}
void main()
{
prime p;
p.readn();
p.display();
getch();
}
| Is This Answer Correct ? | 10 Yes | 18 No |
Post New Answer View All Answers
If dog is a friend of boy and boy is a friend of house, is dog a friend of house?
How do you instruct your compiler to print the contents of the intermediate file showing the effects of the preprocessor?
Explain pass by value and pass by reference.
How do we balance an AVL Tree in C++?
What are literals in C++?
What is the c++ code?
What is the purpose of templates in c++?
Do class method definitions?
Define copy constructor.
Can I create my own functions in c++?
Differences between private, protected and public and give examples.
Can a new be used in place of old mallocq? If yes, why?
Where the memory to the static variables is allocated?
What is cin clear () in c++?
Differentiate between a constructor and a destructor in c++.