C++ Fibonacci Number Sequence using Recursion
###### Posted by Samath
Last Updated: January 05, 2017

The Fibonacci sequence is a series of numbers where a number is found by adding up the two numbers before it. Starting with 0 and 1, the sequence goes 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, and so forth. Written as a rule, the expression is F(n) = F(n-1) + F(n-2).

```#include <iostream>
using namespace std;

int fib(int num)
{
cout << "Finding the fib of " << num << endl;
if(num == 0)
{
cout << "We have reached the termination case of 0. Returning 0" << endl;
return 0;
}

if(num == 1)
{
cout << "We have reached the termination case of 1. Returning 1" << endl;
return 1;
}

int result = fib(num - 1) + fib(num - 2);
cout << "Fib of " << num << " is " << result << endl;
return result;
}

int main()
{
fib(6);
return 0;
}```

###### JavaScript program that returns the nth entry in the Fibonacci sequence
SceDev | Feb 27, 2024
###### Display the first 10 Fibonacci numbers in C++
Samath | Nov 02, 2014
###### C Program to Find Factorial of a Number Using Recursion
Samath | Jan 02, 2017
###### Towers of Hanoi using recursion in C++
Samath | Jan 04, 2017
###### C Program to generate the Fibonacci Series starting from any two numbers
Samath | Jan 02, 2017
###### Java program that read a sequence of integer inputs and print the smallest and largest of the inputs
Samath | Apr 03, 2022
###### Java program that read a sequence of integer inputs and print the number of even and odd inputs.
Samath | Apr 03, 2022
###### Java program that read a five-digit positive integer and breaks it into a sequence of individual digits
Samath | Feb 10, 2021