Jump to content

Nth root: Difference between revisions

m
Line 1,454:
 
=={{header|FutureBasic}}==
<lang futurebasic>window 1
include "ConsoleWindow"
 
def tab 8
 
local fn NthRoot( root as long, a as long, precision as double ) as double
dim as double x0, x1
 
x0 = a : x1 = a /root
while ( abs( x1 - x0 ) > precision )
x0 = x1
x1 = ( ( root -1.0 ) * x1 + a / x1 ^ ( root -1.0 ) ) /root
wend
end fn = x1
 
print " 125th Root of 5643 Precision .001", , using "#.###############"; fn NthRoot( 125, 5642, 0.001 )
print " 125th Root of 5643 Precision .001", , using "#.###############"; fn NthRoot( 125, 5642, 0.001 )
print " 125th Root of 5643 Precision .00001", using "#.###############"; fn NthRoot( 125, 5642, 0.00001 )
print " Cube Root of 27 Precision .00001", using "#.###############"; fn NthRoot( 3, 27, 0.00001 )
Line 1,477 ⟶ 1,474:
print " 10th Root of 1024 Precision .00001", using "#.###############"; fn NthRoot( 10, 1024, 0.00001 )
print " 5th Root of 34 Precision .00001", using "#.###############"; fn NthRoot( 5, 34, 0.00001 )
 
</lang>
HandleEvents</lang>
Output:
<pre>
416

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.