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
What is &x in c++?
List down the guideline that should be followed while using friend function.
Do vectors start at 0 c++?
What is constructor in C++?
How do you generate a random number in c++?
Why are pointers used?
What do you mean by late binding?
Where the memory to the static variables is allocated?
What is c++ programming language?
How the delete operator differs from the delete[]operator?
Can we run c program in turbo c++?
What is the word you will use when defining a function in base class to allow this function to be a polimorphic function?
Explain Memory Allocation in C/C++ ?
What is a memory leak c++?
Which one is a preferred language C or C++? Why?