Created
August 4, 2016 17:12
-
-
Save gerrard00/9ea16d5e85c59740592320c62f3f82ee to your computer and use it in GitHub Desktop.
Fib in c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
int main(int argc, char *argv[]) | |
{ | |
unsigned long int fib(unsigned long int x); | |
char *ptr; | |
unsigned long int input = strtoul(argv[1], &ptr, 10); | |
unsigned long int result = fib(input); | |
printf("result: %lu\n", result); | |
} | |
unsigned long int fib(unsigned long int x) | |
{ | |
if (x <= 1) { | |
return 1; | |
} | |
return fib(x - 1) + fib(x - 2); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment