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. very good cod
View Tutorial          By: moly at 2007-03-13 08:17:40

2. Before i had lot of doubts in abstract class... no
View Tutorial          By: Mohandoss at 2012-04-02 05:08:43

3. i can saved when i run the program...
but w

View Tutorial          By: kathleen ashley at 2010-08-02 05:22:46

4. Thnx Ramlak,but be ware about syntax errors.
View Tutorial          By: Saber at 2008-11-03 07:45:23

5. Your output is not correct.. Give the correct out
View Tutorial          By: Surendrakumar at 2014-06-04 07:00:16

6. Thanx.. it helps me a lot, now.. i have 1 more que
View Tutorial          By: GuzZpaWn at 2012-01-15 17:19:29

7. Thank you. This is really awesome... Helped us a l
View Tutorial          By: Shivakumar at 2012-09-12 15:23:21

8. had the sample problem.. java.io.IOException: HTTP
View Tutorial          By: java at 2012-08-22 09:39:57

9. Hi!
I would like to send a string from a j2

View Tutorial          By: beetlebrain at 2010-03-26 06:02:00

10. Really very nice and step by step explanation hel
View Tutorial          By: sabarish at 2011-11-08 06:47:49