aboutsummaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/fib.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/test/fib.c b/test/fib.c
new file mode 100644
index 0000000..6254a5f
--- /dev/null
+++ b/test/fib.c
@@ -0,0 +1,19 @@
+unsigned fib(unsigned x) {
+ unsigned r = 0, q = 1;
+ while (x--) {
+ unsigned s = r + q;
+ r = q;
+ q = s;
+ }
+ return q;
+}
+
+int atoi(const char *);
+int printf(const char *, ...);
+
+int main(int argc, char **argv) {
+ unsigned n = argv[1] ? atoi(argv[1]) : 10;
+ printf("fib(%u) = %u\n", n, fib(n));
+}
+
+/* vim:set ts=3 sw=3 expandtab: */