functions questions c 2b 2b

Solutions on MaxInterview for functions questions c 2b 2b by the best coders in the world

showing results for - "functions questions c 2b 2b"
Manuel
16 Apr 2016
1#include<iostream>
2using namespace std;
3
4int fib(int x)
5{
6    if(x == 0)
7    {
8        return 0;
9    }
10    else if(x==1)
11    {
12        return 1;
13    }
14    else
15    {
16        return fib(x-1)+fib(x-2);
17    }
18}
19
20int main()
21{
22    cout << fib(0) << "\n";
23    cout << fib(1) << "\n";
24    cout << fib(2) << "\n";
25    cout << fib(3) << "\n";
26    cout << fib(4) << "\n";
27    cout << fib(5) << "\n";
28    return 0;
29}									
30