Comment on Tutorial - Checking Prime Number in C++ By Grant Braught



Comment Added by : Anonymous

Comment Added at : 2013-02-27 05:38:27

Comment on Tutorial : Checking Prime Number in C++ By Grant Braught
This program is mush faster and finer than given program.



#include <iostream>
#include <math.h>

bool IsPrime(int number)
{
for (int i=2; i<sqrt(number/2); i++)
{
if (number % i == 0)
{
return false;
}
}

return true;
}
int main()
{
int number;

cout << \"Enter an integer: \";
cin >> number;

if (IsPrime(number))
cout << number << \" is prime.\" << endl;
else
cout << number << \" is not prime.\" << endl;

return 0;
}


View Tutorial



Ask a Question

Subscribe to Tutorials

Related Tutorials

Program using concept of byte long short and int in java

Update contents of a file within a jar file

Tomcat and httpd configured in port 8080 and 80

Java File

Java String

Count number of vowels, consonants and digits in a String in Java

Reverse a number in Java

Student marks calculation program in Java

Handling Fractions in Java

Calculate gross salary in Java

Calculate average sale of the week in Java

Vector in Java - Sample Program

MultiLevel Inheritance sample in Java

Multiple Inheritance sample in Java

Java program using Method Overriding

Archived Comments

1. It was actually useful!!! Thanks for explaining in
View Tutorial          By: steph at 2010-01-28 21:59:06

2. dear sir, plz answer my following questions:

View Tutorial          By: hawa at 2012-01-29 08:29:39

3. i always encounter a problem every time we discuss
View Tutorial          By: sukira 18 at 2009-08-29 03:25:23

4. can you please e mail me a code about hotel reserv
View Tutorial          By: princeton at 2008-09-19 02:32:13

5. thanks! great tutorial!
View Tutorial          By: Gracia at 2013-01-10 07:58:06

6. HI guys i am also studying c++ And now almost mast
View Tutorial          By: Inayat Ullah at 2011-02-08 09:29:44

7. i have a question..i need to parse an xml file wit
View Tutorial          By: meltd0wn at 2011-09-30 08:36:51

8. Dear Gurus, I have arrived at your site lloking f
View Tutorial          By: Fred Mah at 2012-09-22 07:40:27

9. hai sir... this is ROSHAN I am searching for voice
View Tutorial          By: roshan at 2013-09-25 08:12:55

10. hi,
i have tried to download the sun api fr

View Tutorial          By: raghu at 2009-01-07 05:45:33