X-Language Docs
Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Back to homepage

Fibonacci Sequence

fn main() -> void {
    let x = 9;
	
    io::println(fib(x));
}


fn fib(x: i64) -> i64 {
    let mut f1 = 0;
    let mut f2 = 1;
    let mut fi: i64;
	
    if x == 0 || x == 1 { 
        return x; 
    }
	
    loop i in 2 x {
	fi = f1 + f2;
	f1 = f2;
	f2 = fi;
    }

    return fi;
}