Harmonic series: Difference between revisions
m
Clarified comment and the name of the harmonic_series variable
(Made code more idiomatic and sped it up such that it can now compute the stretch task.) |
m (Clarified comment and the name of the harmonic_series variable) |
||
Line 1,772:
println!("Harmonic number 100 = {}", harmonic_number(100));
//In order to avoid recomputing all the terms in the sum for
//we save the value of the harmonic series between loop iterations
//and just add 1/iter to it.
Line 1,778:
let mut target = 1;
let mut iter = 1;
let mut
while target <= 10 {
if
println!("Position of first term > {target} is {iter}");
target += 1;
Line 1,788:
//Compute the next term in the harmonic series
iter += 1;
}
}
|