How do I test if an integer is composite?

Get help using Construct 2

Post » Wed Feb 10, 2016 1:48 am

I'm making a math game for a school project. Whats the most efficient way to test if a variable is composite, or not prime?
B
10
S
2
Posts: 20
Reputation: 622

Post » Wed Feb 10, 2016 7:23 am

You could try finding the remainder of every number from 2 to one less than the number with a loop. If the remainder is ever 0 then it's a composite.

Global number num=8175
Global number isComposite=0

Repeat num-3 times
Compare num%(loopindex+2) =0
--- stop loop
--- set isComposite to 1
B
91
S
31
G
98
Posts: 5,192
Reputation: 65,170


Return to How do I....?

Who is online

Users browsing this forum: COGames, conker23, loz666, Mogador, Odin, Sumyjkl and 1 guest