| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
An Array of Natural Numbers
Hi, I'm new to this forum, and would really appreciate some assistance. I'm trying to create a program that tests if a number is prime or not. In order to do that, I'm going to need an array containing all natural numbers up to some obscenly large number. I then need to find a way to test the number against all elements of the array, to see if after the decimal place, there is a 0. How would this be done? Thanks in advance
|
|
#2
|
|||
|
|||
|
Well, I think you don't have to get it to so much trouble as I presume that the "math.h" library must have some function or something to test if a number is prime or not. Search in Google or something! Hope I helped!!!
Costas |
|
#3
|
||||
|
||||
|
Hmmm. Not a very efficient method. There are many algorithms that are much more effective, but the simplest (though not necessarily the fastest is something like this:
__________________
This is my code. Is it not nifty? "The biggest problem encountered while trying to design a system that was completely foolproof, was, that people tended to underestimate the ingenuity of complete fools." ---Douglas Adams Join the Itsacon fanclub! Zero Tolerance: Spammers banned so far: 280
![]() |
![]() |
| Viewing: Dev Articles Community Forums > Programming > C/C++ Help > An Array of Natural Numbers |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|