anybody know the algorithm for how to write a function that computes prime numbers? by the way it's for C programming.
thanks!
anybody know the algorithm for how to write a function that computes prime numbers? by the way it's for C programming.
thanks!
doesn't the prof tell you basically how you do it and all you have to do is convert the instruction to C? I remember that's basically how they taught it when i was doing cpsc.
Easiest way (in pseudocode):
Given X, where X is any number that needs to be computed,
Y = X-1
If X modulo Y != 0,
increment a counter
decrement Y, and loop until Y == 0
If the counter == 1, it's a prime (X divisible only by 1 and itself).
Otherwise it's not a prime.
That should work.
thanks a lot man