write the prime no program in c++?

Answer Posted / prits

#include <iostream>
using namespace std;

void main()
{
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;

}

Is This Answer Correct ?    32 Yes 15 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What do you understand by zombie objects in c++?

611


What is pointer to array in c++?

615


What are advantages of using friend classes?

631


Which is best c++ or java?

606


What is abstract class in c++?

581






What is operator overloading in c++ example?

648


total amount of milk produced each morning and then calculates and outputs the number of cartons needed for this milk , the cost of producing the milk and the profit from producing this milk.

2081


What is :: operator in c++?

579


What are static type checking?

628


What is the use of ::(scope resolution operator)?

646


Which is best ide for c++?

566


Can I make ios apps with c++?

555


Why do we use classes in programming?

570


Which header file allows file i/o with streams a) fileio.h b) iostream.h c) fstream.h

655


When is dynamic checking necessary?

597