|
-
Sep 5th, 2012, 05:23 PM
#5
Re: Prime number generator
Mod is short for modulo ... the result is the remainder value of the division operation .... 4 mod 2 is 0 because 4 divided by 2 is 2, no remainder. 5 mod 2 is 1 (5/2 = 2R1).... 7 mod 2 is 1.
As for primes....
First, it can never be an even number... so if the number mod 2 is 0 then it's not a prime (that's why I used 2 in the examples above). 1 is a given, so is 3. So that's where I'd start at...1.... then add 2 each time. After adding 2 to the current number, see if it is divisible by any of the previous primes evenly .. if the mod of any of the primes is 0, then that number is divisible evenly by that number and therefore not a prime.
Now, simply create an array with an upper bound of 25... use one counter to keep track of the index in the array... and loop until you reach 25 on the index.
-tg
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|