d2jsp
Log InRegister
d2jsp Forums > Off-Topic > General Chat > Homework Help > Need Programming Help!!! > Visual Logic
Prev12
Add Reply New Topic New Poll
Member
Posts: 6,325
Joined: Dec 2 2007
Gold: 2,347.75
Nov 19 2014 07:05pm
You can use prime factorization to determine if an integer is a prime
First check if n is either 2,3,5,7 then it is a prime.
then set f = 2
test if n % f = 0. If then it's not a prime
if it's not 0 then set f = 3 and repeat. Do this for f = 2, 3, 5 and 7
when f is > 7 then check if n < 1. If then it's not a prime. Otherwise it's a prime.

Take 20 for instance

f = 2
n = 20

n % f = 0, => not a prime

----

f = 2
n = 19

n % f != 0
f = 3
n % f != 0
f = 5
n % f != 0
f = 7
n % f != 0

n = 19, is a prime since 19 > 1

Hope it helps :)
Member
Posts: 21,893
Joined: Mar 27 2009
Gold: 12,408.00
Nov 19 2014 07:42pm
I = 2 to n
If n mod i = 0 then
not prime
Exit for
Else
Prime
End if
Next n

Can be nested.

This post was edited by Dontrunaway on Nov 19 2014 07:44pm
Go Back To Homework Help Topic List
Prev12
Add Reply New Topic New Poll