Nth root: Difference between revisions
Content deleted Content added
Langurmonkey (talk | contribs) |
Add SmallBASIC |
||
Line 1,038: | Line 1,038: | ||
------------------------- |
------------------------- |
||
144 1 144.000000 |
144 1 144.000000 |
||
144 2 12.000000 |
|||
144 3 5.241483 |
|||
144 4 3.464102 |
|||
144 5 2.701920 |
|||
144 6 2.289428 |
|||
144 7 2.033937 |
|||
144 8 1.861210 |
|||
</pre> |
|||
==={{header|SmallBASIC}}=== |
|||
<syntaxhighlight lang="qbasic"> |
|||
func nthroot(a, n) |
|||
precision = .00001 |
|||
x1 = a |
|||
x2 = a / n |
|||
repeat |
|||
x1 = x2 |
|||
x2 = ((n - 1) * x2 + a / x2 ^ (n - 1)) / n |
|||
until (abs(x2 - x1) < precision) |
|||
return x2 |
|||
end |
|||
print "Finding the nth root of 144" |
|||
print " x n nthroot" |
|||
print "------------------------" |
|||
for n = 2 to 8 |
|||
print using "### #### ###.000000"; 144; n; nthroot(144, n) |
|||
next |
|||
</syntaxhighlight> |
|||
{{out}} |
|||
<pre> |
|||
Finding the nth root of 144 |
|||
x n nthroot |
|||
------------------------- |
|||
144 2 12.000000 |
144 2 12.000000 |
||
144 3 5.241483 |
144 3 5.241483 |