Commit d1bbe2b4 authored by Aral Balkan's avatar Aral Balkan

First solution

parent d4cdb1fd
[[package]]
name = "fibonacci"
version = "0.1.0"
use std::io;
fn f(n:u32) -> u32 {
let mut prev = 0;
let mut current = 1;
for i in 0..n {
let next = prev + current;
prev = current;
current = next;
}
return prev;
}
fn main() {
println!("Hello, world!");
println!("Which Fibonacci number?");
let mut input = String::new();
io::stdin().read_line(&mut input).expect("Error: stdin.");
let n:u32 = input.trim().parse().expect("Error: not a number.");
println!("Fibonacci number at position {} is {}.", n, f(n));
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment