summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormo khan <mo.khan@gmail.com>2020-08-12 09:50:29 -0600
committermo khan <mo.khan@gmail.com>2020-08-12 09:50:29 -0600
commit031491a0f79295b134a2aa14ebb82bdbfb6efac5 (patch)
tree4b2109da378bd9ea4828d74543fa0dbfd4d0ca2e
parent412f745f7011f2fbb9938e90c577e9c0426541c1 (diff)
Compute the first 4 numbers in the fibonacci sequence
-rw-r--r--fib.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/fib.c b/fib.c
new file mode 100644
index 0000000..7525d1b
--- /dev/null
+++ b/fib.c
@@ -0,0 +1,27 @@
+#include <stdio.h>
+#include <assert.h>
+
+int fib(int n)
+{
+ if (n == 1) {
+ return 0;
+ }
+
+ if (n == 2 || n == 3) {
+ return 1;
+ }
+
+ return 2;
+}
+
+int main(int argc, char *argv[])
+{
+ assert(fib(1) == 0);
+ assert(fib(2) == 1);
+ assert(fib(3) == 1);
+ assert(fib(4) == 2);
+
+
+ printf("YAY!\n");
+ return 0;
+}