Square Roots

Author(s): Dick Wagner
Publication: The Plotter
Pub Details: The Plotter v10 n8 (Volume 10, Issue 8)
Pages: 3

The program that generates square roots is probably moot as we have square root capability in our TS computers. This program is mainly of interest in its display of the progress made in arriving at the square root of a number by the division process. It is surprising that the answer is often within 5 tries.

The first try is a random try using a number between 0 and the number chosen (line 90). Then that guess is refined by division as many times as necessary to arrive at the correct number. The printing of the error is done to show how the computer works it out. The computer knows when to stop only when the error is zero, other wise it will keep repeating the same answer.

Readers will recall that the square root of a whole number is, when multiplied by itself, equals that number. This is the method used to arrive at any error that might exist in the answer. Just remember that electronic and mechanical calculators have accuracy limits.

This program requires little memory so it works on the TS 1000 and up.

The basis for this program is from the book “70 GAMES for the Timex/Sinclair 1000 and 1500” by Tim Hartnell.

WHAT NUMBER DO YOU WANT ME TO
FIND THE SQUARE ROOT OF?

THE SQUARE ROOT OF 32:
16.5
ERROR IS -240.25
9.219697
ERROR IS -53.002812
6.3452634
ERROR IS -8.2623681
5.6941976
ERROR IS -0.4238867
5.6569767
ERROR IS -.0013854057
5.6568543
ERROR IS -1.4901161E-8
5.6568542
ERROR IS 0
5.6568542
ERROR IS 0
THE SQUARE ROOT IS 5.6568542
  10 REM TIM HARTNELL'S "SQUARE ROOT SOLVER" IS THE BASIS OF THIS PROGRAM
20 REM SOLVE SQUARE ROOT BY DIVISION
40 PRINT "WHAT NUMBER DO YOU WANT ME TO FIND THE SQUARE ROOT OF?"
60 INPUT B
70 IF B<0 THEN GO TO 60
80 PRINT : PRINT "THE SQUARE ROOT OF ";B;":"
90 LET A=INT (RND*B)+1
100 LET X=B/A
110 LET Y=(X+A)/2
120 PRINT Y
130 PRINT "ERROR IS ";ABS B-Y*Y
135 LET ERROR=ABS B-(Y*Y)
137 IF A=Y THEN GO TO 170
140 LET A=Y
150 GO TO 100
170 PRINT "THE SQUARE ROOT IS ";Y

Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.