write the prime no program in c++?

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


Please Help Members By Posting Answers For Below Questions

What is &x in c++?

768


List down the guideline that should be followed while using friend function.

822


Do vectors start at 0 c++?

744


What is constructor in C++?

832


How do you generate a random number in c++?

830


Why are pointers used?

756


What do you mean by late binding?

841


Where the memory to the static variables is allocated?

781


What is c++ programming language?

827


How the delete operator differs from the delete[]operator?

849


Can we run c program in turbo c++?

808


What is the word you will use when defining a function in base class to allow this function to be a polimorphic function?

905


Explain Memory Allocation in C/C++ ?

819


What is a memory leak c++?

775


Which one is a preferred language C or C++? Why?

834