See all articles from SYNC v1 n4
10 PRINT "SQUARE ROOT OF X"
20 PRINT "ENTER X "; (3 spaces)
30 INPUT X
40 PRINT X
50 LET L=0
60 LET H=182
70 LET T=(L+H)/2
80 LET K=X/T
90 IF K=T THEN GOTO 160
100 IF H-L < 2 THEN GOTO TO 160
110 IF K < T THEN GOTO 140
120 LET L=T
130 GOTO 70
140 LET H=T
150 GOTO 70
160 PRINT "ROOT IS ";T (3 spaces)
170 PRINT
180 STOP
This program operates by means of bisection iteration, which is basically just a variation of the old high-low game. The size limitation of the integer basic (variable size) limits the maximum root to 181.
Besides the mathematical value, this square root program is handy for use as a subroutine to represent the distance between two points (using the Pythagorean theorem) in some game programs in which one might try to guess the location of an object and when in error to find out by how great a margin.
Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.