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. The code is running successfully.........but , I m
View Tutorial          By: Harshita at 2013-03-26 19:25:58

2. Its awesome
View Tutorial          By: Ranjitha at 2012-08-02 10:21:59

3. please gave us simple difference between structure
View Tutorial          By: vishal at 2011-12-18 13:33:17

4. HOW TO SET PASSWORD IN JAVA.....
View Tutorial          By: NAKUL at 2012-12-14 05:23:16

5. Thank you so much Eric Giguere.
You save me

View Tutorial          By: ijAcK D at 2009-10-18 05:02:48

6. thank you for ur programs.........
View Tutorial          By: NAGARAJRATHINARAJ at 2012-01-24 14:39:19

7. Here is my issue. The sql which comes thru the JTD
View Tutorial          By: Kumar at 2012-02-21 02:42:08

8. could you send me a code for a music video mobile
View Tutorial          By: Christian at 2009-08-28 23:03:45

9. Hi,

As you shown here that we have

View Tutorial          By: Keyur at 2011-04-05 03:30:12

10. Nice Example. Gives very clear idea.
View Tutorial          By: Larsen at 2013-09-14 02:29:24