Nth root: Difference between revisions

Content deleted Content added
Chkas (talk | contribs)
Basicgames (talk | contribs)
Line 749: Line 749:
144 8 1.861210
144 8 1.861210
</pre>
</pre>

==={{header|Craft Basic}}===
<syntaxhighlight lang="basic">precision 6

let a = int(rnd * 5999) + 2

print "calculating nth root of ", a, "..."

for n = 1 to 10

gosub nroot
print n, " : ", y

next n

end

sub nroot

let p = .00001

let x = a
let y = a / n

do

if abs(x - y) > p then

let x = y
let y = ((n - 1) * y + a / y ^ (n - 1)) / n

endif

wait

loop abs(x - y) > p

return</syntaxhighlight>


==={{header|FreeBASIC}}===
==={{header|FreeBASIC}}===