write the prime no program in c++?

Answer Posted / tuhin pal chowdhury

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int num;
int flag = 0;
cout<<"Enter a number"<<endl;
cin>>num;
for(int i=2;i<num;i++)
{
if((num%i) == 0)
{
flag = 1;
break;
}
}
if (flag == 1)
cout<<"Not Prime"<<endl;
else
cout<<"Prime"<<endl;
getch();
}

Is This Answer Correct ?    1 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Can member data be public?

599


Where and why do I have to put the "template" and "typename" keywords?

586


What is a responder chain?

578


What is pointer -to-members in C++? Give their syntax?

599


Search for: what is pair in c++?

595






What is vectorial capacity?

653


Explain pass by value and pass by reference.

597


What doescout<<(0==0) print out a) 0 b) 1 c) Compiler error: Lvalue required

575


What is c++ hash?

624


Write about an iterator class?

614


Explain about Garbage Collector?

651


What are the benefits of operator overloading?

682


Can char be a number c++?

599


What is the extraction operator and what does it do?

614


Incase of a function declaration, what is extern means?

521