Monday, May 24, 2010

How would you define a prime number in a program?

I know what a prime number is, of course, but I don't know how to tell the program what is a prime number and what isn't. I'm writing in C++. Any help would be so awesome, thank you!

How would you define a prime number in a program?
This is just a general way. I would start with the first prime of 2 and put it in a table. Then starting with 3 and every odd number above it try to divide it by every number in the table up to its square root. If nothing divides into it then it is prime and should be added to the table.



Reply:If you know what a prime number is, then the rest should be obvious


No comments:

Post a Comment