Skip to content
Switch branches/tags
Go to file
Cannot retrieve contributors at this time
# Square Root Calculator
# by Martin del Rio
# Created for LDPL 1.0
# Square-root sub-procedure
sqrt/radicand is number
sqrt/result is number
sqrt/aux is number
sqrt/last-value is number
# Ask for a number
display "Enter a number: "
accept sqrt/radicand
# Declare square root subprocedure
# Calculates the square root of a radicand using the babylonian method
# Input parameter:
# - sqrt/radicand: the number to be square-rooted (preserved)
# Output parameter:
# - sqrt/result: the square root of the given number
sub-procedure square-root
if sqrt/radicand is equal to 0 then
store 0 in sqrt/result
end if
store 0 in sqrt/last-value
store 1 in sqrt/result
while 1 is equal to 1 do
in sqrt/aux solve sqrt/radicand / sqrt/result
in sqrt/result solve sqrt/aux + sqrt/result
in sqrt/result solve sqrt/result / 2
if sqrt/result is not equal to sqrt/last-value then
store sqrt/result in sqrt/last-value
end if
end sub-procedure
# Calculate square root of the entered number
call sub-procedure square-root
display "sqrt(" sqrt/radicand ") = " sqrt/result crlf