Task

Implement the algorithm to compute the principal   nth   root   





A

n





{\displaystyle {\sqrt[{n}]{A}}}

   of a positive real number   A,   as explained at the   Wikipedia page.



function nth_root(n, a)
    precision = 0.0001
 
    dim x(2)
    x[0] = a
    x[1] = a /n
    while abs(x[1] - x[0]) > precision
        x[0] = x[1]
        x[1] = ((n -1.0) * x[1] +a / x[1]^(n -1.0)) / n
    end while
    return x[1]
end function
 
print "  n    5643 ^ 1 / n        nth_root ^ n"
print " --------------------------------------"
for n = 3 to 11 step 2
    tmp = nth_root(n, 5643)
    print " "; n; "    "; tmp; chr(9); (tmp ^ n)
next n
print
for n = 25 to 125 step 25
    tmp = nth_root(n, 5643)
    print n; "    "; tmp; chr(9); (tmp ^ n)
next n