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 Nroot (n, a)
    LET precision = .00001
 
    LET x1 = a
    LET x2 = a / n
    DO WHILE ABS(x2 - x1) > precision
       LET x1 = x2
       LET x2 = ((n - 1) * x2 + a / x2 ^ (n - 1)) / n
    LOOP
    LET Nroot = x2
END FUNCTION
 
PRINT "   n    5643 ^ 1 / n     nth_root ^ n"
PRINT " ------------------------------------"
FOR n = 3 TO 11 STEP 2
    LET tmp = Nroot(n, 5643)
    PRINT USING "####": n;
    PRINT "    ";
    PRINT USING "###.########": tmp;
    PRINT "    ";
    PRINT USING "####.########": (tmp ^ n)
NEXT n
PRINT
FOR n = 25 TO 125 STEP 25
    LET tmp = Nroot(n, 5643)
    PRINT USING "####": n;
    PRINT "    ";
    PRINT USING "###.########": tmp;
    PRINT "    ";
    PRINT USING "####.########": (tmp ^ n)
NEXT n
END