Prime number check


using namespace std;
long num;

string isPrime(long);

       cout<<"Enter a number: ";
       cout<<"\n\nIs prime? " << isPrime(num);      

string isPrime(long x){
    string prime = "false";
     for(int i=2; i*i < x; i++) //no need to divide by all numbers 
             prime = (x % i ==0) ? "false": "true";
     return prime;        

About praveenaj

I'm just an average guy who enjoys doing Programming/Web Designs/Pencil art & drinking coffee :)
This entry was posted in Uncategorized and tagged , . Bookmark the permalink.

3 Responses to Prime number check

  1. Nice work man.. What is da functionality of dis string header ?

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s