aboutsummaryrefslogtreecommitdiff
path: root/tcc/examples/fib.c
diff options
context:
space:
mode:
authorIndrajith K L2022-12-03 17:00:20 +0530
committerIndrajith K L2022-12-03 17:00:20 +0530
commitf5c4671bfbad96bf346bd7e9a21fc4317b4959df (patch)
tree2764fc62da58f2ba8da7ed341643fc359873142f /tcc/examples/fib.c
downloadcli-tools-windows-f5c4671bfbad96bf346bd7e9a21fc4317b4959df.tar.gz
cli-tools-windows-f5c4671bfbad96bf346bd7e9a21fc4317b4959df.tar.bz2
cli-tools-windows-f5c4671bfbad96bf346bd7e9a21fc4317b4959df.zip
Adds most of the toolsHEADmaster
Diffstat (limited to 'tcc/examples/fib.c')
-rw-r--r--tcc/examples/fib.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/tcc/examples/fib.c b/tcc/examples/fib.c
new file mode 100644
index 0000000..8da26bc
--- /dev/null
+++ b/tcc/examples/fib.c
@@ -0,0 +1,24 @@
+#include <stdio.h>
+#include <stdlib.h> // atoi()
+
+int fib(n)
+{
+ if (n <= 2)
+ return 1;
+ else
+ return fib(n-1) + fib(n-2);
+}
+
+int main(int argc, char **argv)
+{
+ int n;
+ if (argc < 2) {
+ printf("usage: fib n\n"
+ "Compute nth Fibonacci number\n");
+ return 1;
+ }
+
+ n = atoi(argv[1]);
+ printf("fib(%d) = %d\n", n, fib(n));
+ return 0;
+}