24 lines
438 B
Plaintext
24 lines
438 B
Plaintext
data 10, 1024, 3, 27, 2, 2, 125, 5642, 4, 16, 0, 0
|
|
|
|
do
|
|
read e, b
|
|
if e = 0 break
|
|
print "The ", e, "th root of ", b, " is ", b^(1/e), " (", nthroot(b, e), ")"
|
|
loop
|
|
|
|
|
|
sub nthroot(y, n)
|
|
local eps, x, d, e
|
|
|
|
eps = 1e-15 // relative accuracy
|
|
x = 1
|
|
repeat
|
|
d = ( y / ( x^(n-1) ) - x ) / n
|
|
x = x + d
|
|
e = eps * x // absolute accuracy
|
|
|
|
until(not(d < -e or d > e ))
|
|
|
|
return x
|
|
end sub
|