tasks a-s
This commit is contained in:
parent
47bf37c096
commit
b83f433714
12433 changed files with 156208 additions and 123 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