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



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. In the above example..where you make the GC1 objec
View Tutorial          By: prasad at 2014-12-11 11:12:28

2. I need a sample jsp(using Struts html tags) in thr
View Tutorial          By: Anil Kumar at 2008-10-23 04:14:51

3. i want java code for day planner please send me on
View Tutorial          By: sumaiya pathan at 2010-10-15 21:34:23

4. very good example and explanation. This kind of p
View Tutorial          By: jagdish at 2011-07-03 15:15:02

5. method overloading possible across classes????
View Tutorial          By: Rohit at 2011-01-26 20:23:02

6. Dude,
Atleast indent and try to make sense

View Tutorial          By: Phani at 2015-03-19 16:51:57

7. Thanks,
But i would like to use an array li

View Tutorial          By: Gustavo at 2011-06-15 21:03:20

8. Hi,

can we use only code given belo

View Tutorial          By: Mahendra at 2012-05-24 10:57:25

9. It's very helpful to me... Thanks...
View Tutorial          By: Nicks Patel at 2010-03-24 23:37:04

10. HI EVERY ONE I AM NEW IN J2ME SO I WANT TO LEARN S
View Tutorial          By: KALAI at 2011-04-04 03:10:32