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.



 
program nth
#
integer root 
real    number, precision
real    temp0, temp1
 
1 format('Enter the base number: ')
2 format('Enter the desired root: ')
3 format('Enter the desired precision: ')
4 format(F12.6)
5 format(I6)
write(6,1)
read(5,4)number
write(6,2)
read(5,5)root
write(6,3)
read(5,4)precision
 
temp0 = number
temp1 = number/root
 
while ( abs(temp0 - temp1) > precision )
   {
      temp0 = temp1
      temp1 = ((root - 1.0) * temp1 + number / temp1 ** (root - 1.0)) / root
   }
 
6 format('  number      root    precision')
write(6,6)
7 format(f12.6,i6,f12.6)
write (6,7)number,root,precision
8 format('The root is: ',F12.6)
write (6,8)temp1
 
end
 