mirror of
https://github.com/TheAlgorithms/C
synced 2024-11-22 05:21:49 +03:00
Add a Fibonacci algorithm
This commit is contained in:
parent
06f872bb8b
commit
cc5da4ce21
19
fib.c
Normal file
19
fib.c
Normal file
@ -0,0 +1,19 @@
|
||||
#include <stdio.h>
|
||||
|
||||
//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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user