Apply the mathematical formula to find fibonacci of the given number using recursive functions? Sample 1 Input : 5, Output : 3. Sample 2 Input : 12, Output : 144
#include<stdio.h>
int Fibonacci(int n){
if ( n == 0 ){
return 0;
}else if ( n == 1 ){
return 1;
}
return (Fibonacci(n-1) + Fibonacci(n-2));
}
int main(){
int n;
scanf("%d",&n);
if(n<10){
n-=1;
}
printf("Fibonacci number: %d\n", Fibonacci(n));
scanf("%d",&n);
return 0;
}
Comments
Leave a comment