Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
13
Task/Nth-root/D/nth-root.d
Normal file
13
Task/Nth-root/D/nth-root.d
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
import std.stdio, std.math;
|
||||
|
||||
real nthroot(in int n, in real A, in real p=0.001) pure nothrow {
|
||||
real[2] x = [A, A / n];
|
||||
while (abs(x[1] - x[0]) > p)
|
||||
x = [x[1], ((n - 1) * x[1] + A / (x[1] ^^ (n-1))) / n];
|
||||
return x[1];
|
||||
}
|
||||
|
||||
void main() {
|
||||
writeln(nthroot(10, 7131.5 ^^ 10));
|
||||
writeln(nthroot(6, 64));
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue