Add fib example
This commit is contained in:
parent
016929a4c0
commit
45c3d5a126
28
examples/fib/fib.mc
Normal file
28
examples/fib/fib.mc
Normal 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;
|
||||
}
|
1
examples/fib/fib.stdin.txt
Normal file
1
examples/fib/fib.stdin.txt
Normal file
@ -0,0 +1 @@
|
||||
11
|
2
examples/fib/fib.stdout.txt
Normal file
2
examples/fib/fib.stdout.txt
Normal file
@ -0,0 +1,2 @@
|
||||
Please enter a number:
|
||||
fib(11) = 89
|
Loading…
Reference in New Issue
Block a user