Skip to content

Instantly share code, notes, and snippets.

@gerrard00
Created August 4, 2016 17:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gerrard00/9ea16d5e85c59740592320c62f3f82ee to your computer and use it in GitHub Desktop.
Save gerrard00/9ea16d5e85c59740592320c62f3f82ee to your computer and use it in GitHub Desktop.
Fib in c
#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