Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
23
Task/Nth-root/Icon/nth-root.icon
Normal file
23
Task/Nth-root/Icon/nth-root.icon
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
procedure main()
|
||||
showroot(125,3)
|
||||
showroot(27,3)
|
||||
showroot(1024,10)
|
||||
showroot(39.0625,4)
|
||||
showroot(7131.5^10,10)
|
||||
end
|
||||
|
||||
procedure showroot(a,n)
|
||||
printf("%i-th root of %i = %i\n",n,a,root(a,n))
|
||||
end
|
||||
|
||||
procedure root(a,n,p) #: finds the n-th root of the number a to precision p
|
||||
if n < 0 | type(n) !== "integer" then runerr(101,n)
|
||||
if a < 0 then runerr(205,a)
|
||||
/p := 1e-14 # precision
|
||||
xn := a / real(n) # initial guess
|
||||
while abs(a - xn^n) > p do
|
||||
xn := ((n - 1) * (xi := xn) + a / (xi ^ (n-1))) / real(n)
|
||||
return xn
|
||||
end
|
||||
|
||||
link printf
|
||||
Loading…
Add table
Add a link
Reference in a new issue