Algorithms
Square Root Algorithm

 read n,
tolerance (n is number for which square root is needed)
 above <
n
 below <1
 square < ?? (what value should we use?)
 repeat until
squaretolerance
<
n < square+tolerance

middle
< (above + below) ÷ 2

square
<
middle x middle

if
square
>
n then

above < middle

else

below < middle (end if) (end until)
 write middle
 stop

The key point to argue
is termination. Clearly we must have tolerance > 0 to guarantee
termination. Prove this to yourself!
CS1104
Main Page
Last Updated 01/05/2000
©
L.Heath, 2000