Something went wrong. Try again.
This string has no description
Something went wrong. Try again.
1.3 kB · 85 lines · Created 1y ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586// You can link any symbol from libc here
extern fn putchar(c: uint);
fn main() { n := 0; while n != 10 { res := fibo(n); print_num(res); // newline putchar(10); n = n + 1; }}
fn num_to_ascii(n: uint) uint /*Option<uint>*/ { if n <= 9 { num_ascii_base := 48; // Some(num_ascii_base + n) num_ascii_base + n } else { // None 21 }}
fn print_num_rev(n: uint) { if n == 0 { putchar(num_to_ascii(0)); } else { while n != 0 { rest := n % 10; n = n / 10; putchar(num_to_ascii(rest)); } };}
fn print_num(n: uint) { if n == 0 { putchar(num_to_ascii(0)); return; };
// Calculate the divisor to get the most significant digit divisor := 1; temp := n; while temp >= 10 { temp = temp / 10; divisor = divisor * 10; };
// Reset temp to original number temp = n;
// Print each digit from most to least significant while divisor > 0 { digit := temp / divisor; // Get the current most significant digit putchar(num_to_ascii(digit)); // Remove the most significant digit temp = temp % divisor; // Reduce divisor divisor = divisor / 10; };}
fn fibo(n: uint) uint { a := 0; b := 1;
while n != 0 { next := a + b; a = b; b = next;
n = n - 1; }
b}