RosettaCodeData/Task/Nth-root/Chipmunk-Basic/nth-root.basic

21 lines
583 B
Plaintext

10 rem Nth root
20 print "Finding the nth root of 144 to 6 decimal places"
30 print " x n root"
40 print "------------------------"
50 for i = 1 to 8
60 print using "### ";144;
70 print using "#### ";i;
80 print using "###.######";nthroot(i,144,1.000000E-07)
90 next i
100 end
1000 sub nthroot(n,x,precision)
1010 rem Returns the nth root of value x to stated precision
1020 x0 = x
1030 x1 = x/n ' - initial guess
1040 while abs(x1-x0) > precision
1050 x0 = x1
1060 x1 = ((n-1)*x1+x/x1^(n-1))/n
1070 wend
1080 nthroot = x1
1090 end sub