[VB6]Prime Number Calculation (code help)

Newbie Spellweaver
Joined
Oct 16, 2008
Messages
85
Reaction score
0
Well my teacher is giving me two projects....this one is specifically supposed to be a challenge (and I agree) and the other thread which was pretty simple in the end.

I need to calculate all the prime numbers between 0 and 100.

For those that don't know what prime numbers are....

Prime numbers are numbers that can be divided by any number and will never equal a whole number.
.....
.....
.....
I think.

Is it possible for me to write..

Code:
If x/1 = INT then
      Bla bla bla
End if

can I write an If/Then statement saying if the numbers comes out an integer (No decimal places) then it does yada yada yada?

Help is always appreciated.

Thanks in advance.
~~Wymm
 
This project is different from the other. The other is for a grade. This isn't. This is in visual BASIC coding (@ s-p-n). Fed I would appreciate help. Negata thanks for trying but I have no idea what modulo is. We haven't even touched that. Fed PM me on msn when you're there ;3
 
Dude that is awesome. The answer is RIGHT THERE...Now I just need to sit for a while and think of how to write it in code. Thanks again.

Sincerely,
~~Wymm
 
Dude that is awesome. The answer is RIGHT THERE...Now I just need to sit for a while and think of how to write it in code. Thanks again.

Sincerely,
~~Wymm

It's a common algorithm, and a common implementation is to keep a list of current primes (start with adding 2), then iterate from 5 to n (n being your 100 here), then try to divide n by every number in your prime list up to the sqrt(n), using modulo, if the result is never 0 (ie, it's indivisible by any known primes), then it is prime, add it to the list, and continue.
 
I have no idea what Modulo is though. I think I know why he gave me this as a challenge though. >_>...

PHP:
a Mod b


With both a and b being integer values, will give a modulus b. This is just the remainder after dividing a by b, so 5 mod 3 is 2, and 5 mod 7 is 5. If a mod b == 0, then a = n*b, for some integer n.
 
Back