Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
17
Task/Nth-root/Rust/nth-root.rust
Normal file
17
Task/Nth-root/Rust/nth-root.rust
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
// 20210212 Rust programming solution
|
||||
|
||||
fn nthRoot(n: f64, A: f64) -> f64 {
|
||||
|
||||
let p = 1e-9_f64 ;
|
||||
let mut x0 = A / n ;
|
||||
|
||||
loop {
|
||||
let mut x1 = ( (n-1.0) * x0 + A / f64::powf(x0, n-1.0) ) / n;
|
||||
if (x1-x0).abs() < (x0*p).abs() { return x1 };
|
||||
x0 = x1
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
println!("{}", nthRoot(3. , 8. ));
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue