ELEC40006-P1-CW/testing/fibonacci.cpp
2020-06-10 20:10:34 +01:00

24 lines
280 B
C++

#include <iostream>
using namespace std;
/*
Takes one input via stdin, the integer n
*/
int fib(const int n){
int y;
if (n <= 1) {
y = 1;
}else {
y = fib(n-1);
y = y + fib(n-2);
}
return y;
}
int main(){
int n;
cin >> n;
cout << fib(n) << endl;
}