Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
23
Task/Nth-root/Yabasic/nth-root.basic
Normal file
23
Task/Nth-root/Yabasic/nth-root.basic
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
data 10, 1024, 3, 27, 2, 2, 125, 5642, 4, 16, 0, 0
|
||||
|
||||
do
|
||||
read e, b
|
||||
if e = 0 break
|
||||
print "The ", e, "th root of ", b, " is ", b^(1/e), " (", nthroot(b, e), ")"
|
||||
loop
|
||||
|
||||
|
||||
sub nthroot(y, n)
|
||||
local eps, x, d, e
|
||||
|
||||
eps = 1e-15 // relative accuracy
|
||||
x = 1
|
||||
repeat
|
||||
d = ( y / ( x^(n-1) ) - x ) / n
|
||||
x = x + d
|
||||
e = eps * x // absolute accuracy
|
||||
|
||||
until(not(d < -e or d > e ))
|
||||
|
||||
return x
|
||||
end sub
|
||||
Loading…
Add table
Add a link
Reference in a new issue