Skip to content

Commit

Permalink
Merge pull request ambujraj#142 from SebastianBrueggemann/patch-1
Browse files Browse the repository at this point in the history
Added Fibonacci series in Rust
  • Loading branch information
ambujraj authored Oct 2, 2018
2 parents ede5583 + d5ea2d6 commit 2f5e62e
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions fibonacci/fibonacci.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
fn fibonacci_match(n: u32) -> u32{
match n{
0 => 0,
1 => 1,
_ => fibonacci_match(n - 1) + fibonacci_match(n-2),
}
}

fn fibonacci_loop(n: u32) -> u32{
let mut sum: u32 = 0;
let mut n1: u32 = 0;
let mut n2: u32 = 1;
for _i in 1..n {
sum = n1 + n2;
n1 = n2;
n2 = sum;
}
return sum;
}

0 comments on commit 2f5e62e

Please sign in to comment.