Fibonacci Numbers
#include <bits/stdc++.h>
using namespace std ;
int fib(int n){
//Base case
if (n==0) return 0;
if (n==1) return 1;
//Recursive case
int smallOutput1 = fib(n-1);
int smallOutput2 = fib(n-2);
//Calculation
return smallOutput1 + smallOutput2 ;
}
int main(){
int n ;
cin >> n ;
cout << fib(n) << '\n';
return 0 ;
}
Comments
Post a Comment