Skip to content

Commit

Permalink
Merge pull request tanwanimohit#20 from Caps-Looking/issue/fibonacci_…
Browse files Browse the repository at this point in the history
…rust

Adding fibonacci in rust
  • Loading branch information
tanwanimohit authored Oct 6, 2019
2 parents ceb5583 + 600ad52 commit 862d271
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions Rust/fibonacci.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use std::io;
use std::io::prelude::*;

fn main() {
print!("Enter the amount of numbers to generate Fibonacci sequence: ");
io::stdout().flush().unwrap();
let mut amount = String::new();

io::stdin().read_line(&mut amount)
.expect("Fail to read line!");

let amount: u32 = amount.trim().parse()
.expect("Please, enter a number!");

for i in 0 .. amount {
print!("{} ", fibonacci(i + 1));
}
}

fn fibonacci(num: u32) -> u32 {
match num {
1 => 1,
2 => 1,
_ => fibonacci(num - 1) + fibonacci(num - 2)
}
}

0 comments on commit 862d271

Please sign in to comment.