daily pastebin goal
4%
SHARE
TWEET

[Rust] Recursion demo

cwchen Aug 23rd, 2017 131 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. fn fib(n: u32) -> u32 {
  2.     if n == 0 { // Base condition 1
  3.         0
  4.     } else if n == 1 { // Base condition 2
  5.         1
  6.     } else {
  7.         fib(n - 1) + fib(n - 2)
  8.     }
  9. }
  10.  
  11. fn main() {
  12.     for i in 0..11 {
  13.         print!("{} ", fib(i));
  14.     }
  15.     println!("");
  16. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top