summary refs log tree commit diff stats
path: root/tinyc/win32/examples/fib.c
diff options
context:
space:
mode:
Diffstat (limited to 'tinyc/win32/examples/fib.c')
-rw-r--r--tinyc/win32/examples/fib.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/tinyc/win32/examples/fib.c b/tinyc/win32/examples/fib.c
new file mode 100644
index 000000000..6a4bdf5c4
--- /dev/null
+++ b/tinyc/win32/examples/fib.c
@@ -0,0 +1,24 @@
+#include <stdio.h>
+#include <math.h>
+
+int fib(int 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;
+}