About cookies

The NCETM site uses cookies. Read more about our privacy policy

Please agree to accept our cookies. If you continue to use the site, we'll assume you're happy to accept them.

 

Personal Learning Login






Sign Up | Forgotten password?
 
Register with the NCETM

AS/A Level Further Mathematics Forum


Only logged in users can post to this forum.

Decision Maths Algorithm - Pseudo Code - Square Nums

tebejo 16 July 2014 19:33
Posts1
Joined07/04/13

Hi,

Apparently the code below discovers square numbers by virtue of always having an odd number of improper factors (a mathematical fact with which I'm fully on board). 

Please, please please could someone explain what is happening with it!!  I'm no stranger to computer code but this is just not making sense to me!

INPUT n

LET J=1

REPEAT

     LET X(J) = 0

     LET J = J+1

UNTIL J=n+1

REPEAT

     LET K=J

     REPEAT

              LET X(K)=1-X(K)

              LET K=K+J

     UNTIL K>n

     LET J =J+1

UNTIL J =n+1

Link to this Post   Report this post Report this post