From cc5da4ce21c23328fef301f0ac2b407ceeeb318b Mon Sep 17 00:00:00 2001 From: Luiz Carlos Aguiar Date: Tue, 4 Jul 2017 17:18:46 -0300 Subject: [PATCH] Add a Fibonacci algorithm --- fib.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 fib.c diff --git a/fib.c b/fib.c new file mode 100644 index 00000000..bc2a6000 --- /dev/null +++ b/fib.c @@ -0,0 +1,19 @@ +#include + +//Fibonnacci function +int fib(int number){ + if(number==1||number==2) return 1; + else return fib(number-1)+fib(number-2); +} + +int main(){ + int number; + + //Asks for the number that is in n position in Fibonnacci sequence + printf("Number: "); + scanf("%d", &number); + + printf("%d \n", fib(number)); + + return 0; +} \ No newline at end of file