Fibonacci numbers in Rust
Example for versions
Rust 0.1
This example calculates Fibonacci numbers recursively.
use std;
import std::io;
fn fibonacci(x: int) -> int {
if (x <= 2) {
ret 1;
} else {
ret fibonacci(x - 1) + fibonacci(x - 2);
}
}
fn main() {
let i = 1;
while i <= 16 {
io::print(#fmt("%d, ", fibonacci(i)));
i = i + 1;
}
io::println("...");
}
Comments
]]>blog comments powered by Disqus
]]>