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

How many types of modularization are there in c++?

566


What do you mean by translation unit in c++?

677


How to declare a function pointer?

581


Why is c++ not purely object oriented?

573


What is pointer to array in c++?

623






Which bit wise operator is suitable for putting on a particular bit in a number?

725


What things would you remember while making an interface?

566


Explain friend class?

634


How a modifier is similar to mutator?

648


What are the two types of comments?

578


What is c++ vb?

616


How many standards of c++ are there?

629


Can you overload the operator+ for short integers?

600


What is the difference between a type-specific template friend class and a general template friend class?

564


What is abstraction c++?

594