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 is setf in c++?

584


How do you print a string on the printer?

582


Const char *p , char const *p What is the difference between the above two?

665


What do you mean by vtable and vptr in c++?

625


what is COPY CONSTRUCTOR and what is it used for?

623






Is c++ a pure oop language?

602


Differentiate between a copy constructor and an overloaded assignment operator.

645


What is the object serialization?

629


How do I tokenize a string in c++?

610


Define pre-condition and post-condition to a member function in c++?

667


Perform addition, multiplication, subtraction of 2-D array using Operator Overloading.

3375


What is the difference between C and CPP?

635


Write a Program for dynamically intialize a 2 dimentional array. Eg:5x20, accept strings and check for vowels and display the no.finally free the space allocated .

684


what is data abstraction in C++?

654


What do you mean by function pointer?

599