# C++ Program to Find Fibonacci Numbers using Recursion

«
»
This C++ Program demonstrates the the computation of Fibonacci Numbers using Recursion.

Here is source code of the C++ Program to Find Fibonacci Numbers using Recursion. The C++ program is successfully compiled and run on a Linux system. The program output is also shown below.

1. `/* `
2. ` * C++ Program to Find Fibonacci Numbers using Recursion`
3. ` */`
4. `#include <cstring>`
5. `#include <iostream>`
6. `#include <cstdlib>`
7. `#define ll long long`
8. `using namespace std;`
9. ` `
10. `/* `
11. ` * Recursive function to find Fibonnaci Numbers`
12. ` */`
13. `ll fibo_recur(int n)`
14. `{`
15. `    if (n == 1 || n == 2)`
16. `        return 1;`
17. `    else`
18. `        return fibo_recur(n - 1) + fibo_recur(n - 2);;`
19. `}`
20. `/* `
21. ` * Main`
22. ` */`
23. `int main()`
24. `{`
25. `    int n;`
26. `    while (1)`
27. `    {`
28. `        cout<<"Enter the integer n to find nth fibonnaci no.(0 to exit): ";`
29. `        cin>>n;`
30. `        if (n == 0)`
31. `            break;`
32. `        cout<<fibo_recur(n)<<endl;`
33. `    }`
34. `    return 0;`
35. `}`

```\$ g++ fibo_recur.cpp
\$ a.out

Enter the integer n to find nth fibonnaci no.(0 to exit): 1
1
Enter the integer n to find nth fibonnaci no.(0 to exit): 2
1
Enter the integer n to find nth fibonnaci no.(0 to exit): 3
2
Enter the integer n to find nth fibonnaci no.(0 to exit): 4
3
Enter the integer n to find nth fibonnaci no.(0 to exit): 5
5
Enter the integer n to find nth fibonnaci no.(0 to exit): 6
8
Enter the integer n to find nth fibonnaci no.(0 to exit): 7
13
Enter the integer n to find nth fibonnaci no.(0 to exit): 8
21
Enter the integer n to find nth fibonnaci no.(0 to exit): 9
34
Enter the integer n to find nth fibonnaci no.(0 to exit): 10
55
Enter the integer n to find nth fibonnaci no.(0 to exit): 0

------------------
(program exited with code: 1) 