Add fib example

This commit is contained in:
Alex Hirsch 2020-02-13 22:31:21 +01:00
parent 016929a4c0
commit 45c3d5a126
3 changed files with 31 additions and 0 deletions

28
examples/fib/fib.mc Normal file
View File

@ -0,0 +1,28 @@
int fib(int n)
{
if (n < 2) {
return n;
}
return fib(n - 1) + fib(n - 2);
}
int main()
{
print("Please enter a number: ");
int n;
n = read_int();
print_nl();
int result;
result = fib(n);
print("fib(");
print_int(n);
print(") = ");
print_int(result);
print_nl();
return 0;
}

View File

@ -0,0 +1 @@
11

View File

@ -0,0 +1,2 @@
Please enter a number:
fib(11) = 89