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.



WRITE(Messagebox) NthRoot(5, 34)
WRITE(Messagebox) NthRoot(10, 7131.5^10)
 
FUNCTION NthRoot(n, A)
   REAL :: prec = 0.001
 
   IF( (n > 0) * (A > 0) ) THEN
       NthRoot = A / n
       DO i = 1, 1/prec
         x = ((n-1)*NthRoot + A/(NthRoot^(n-1))) / n
         IF( ABS(x - NthRoot) <= prec ) THEN
             RETURN
         ENDIF
         NthRoot = x
       ENDDO
   ENDIF
 
   WRITE(Messagebox, Name) 'Cannot solve problem for:', prec, n, A
END