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
How do you compile the source code with your compiler?
Can class objects be passed as function arguments?
Why is c++ is better than c?
Does c++ have foreach?
Which software is best for c++ programming?
What is the use of c++ programming language in real life?
Can we use this pointer inside static member function?
Is c or c++ more useful?
Is c++ still being used?
What is the purpose of the "delete" operator?
What is the outcome of cout< a) 16 b) 17 c) 16.5
When is the destructor called?
Comment on local and global scope of a variable.
Write a program for Divide a number with 2 and Print the output ( NOTE: Check for divide by zero error).
why is iostream::eof inside a loop condition considered wrong?