mirror of
https://github.com/theoludwig/programming-challenges.git
synced 2024-12-08 00:45:29 +01:00
21 lines
487 B
Rust
21 lines
487 B
Rust
use std::io;
|
|
|
|
pub fn fibonacci(number: u32) -> u32 {
|
|
if number == 0 || number == 1 {
|
|
return number;
|
|
}
|
|
return fibonacci(number - 1) + fibonacci(number - 2);
|
|
}
|
|
|
|
fn main() {
|
|
let mut number = String::new();
|
|
io::stdin()
|
|
.read_line(&mut number)
|
|
.expect("Failed to read `stdin` line.");
|
|
let number: u32 = number
|
|
.trim()
|
|
.parse()
|
|
.expect("Failed to convert `number` as an `u32`.");
|
|
println!("{}", fibonacci(number));
|
|
}
|