3b03d43dd1
- hello.bux: Hello World with PrintLine - fibonacci.bux: Recursive Fibonacci with while loop - factorial.bux: Recursive Factorial computation - structs.bux: Struct creation and field access All examples compile and run successfully via 'bux run'
25 lines
505 B
Plaintext
25 lines
505 B
Plaintext
// Fibonacci - Recursive function with while loop
|
|
extern func Std_Io_PrintLine(s: String);
|
|
extern func Std_Io_PrintInt(n: int);
|
|
|
|
func Fibonacci(n: int) -> int {
|
|
if n <= 1 {
|
|
return n;
|
|
}
|
|
return Fibonacci(n - 1) + Fibonacci(n - 2);
|
|
}
|
|
|
|
func Main() -> int {
|
|
Std_Io_PrintLine("Fibonacci sequence:");
|
|
|
|
var i: int = 0;
|
|
while i < 10 {
|
|
let fib: int = Fibonacci(i);
|
|
Std_Io_PrintInt(fib);
|
|
Std_Io_PrintLine("");
|
|
i = i + 1;
|
|
}
|
|
|
|
return 0;
|
|
}
|