[Exercise] - Adding fibonacci program
This commit is contained in:
parent
d0a0d267da
commit
4c48c1b0af
22
fib/main.rs
Normal file
22
fib/main.rs
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
const GOLDEN_RATIO:f32 = 1.6180339887;
|
||||||
|
const GOLDEN_CONJUGATE:f32 = -0.6180339887;
|
||||||
|
const FIVE_SQRT:f32 = 2.236067977;//√5
|
||||||
|
fn fib(n:f32) -> f32 {
|
||||||
|
return (GOLDEN_RATIO.powf(n) - GOLDEN_CONJUGATE.powf(n)) / FIVE_SQRT;
|
||||||
|
}
|
||||||
|
fn main(){
|
||||||
|
let args: Vec<String> = std::env::args().collect();
|
||||||
|
let input = args.get(1);
|
||||||
|
match input {
|
||||||
|
Some (inStr) => {
|
||||||
|
match inStr.trim().parse() {
|
||||||
|
Ok (n) => {
|
||||||
|
let result = fib(n);
|
||||||
|
println!("fib({}) = {:.2}",n,result);
|
||||||
|
},
|
||||||
|
Err(err) => println!("can't parse value to float: {}",err)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
None => println!("fib [LIMIT]")
|
||||||
|
};
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user