Fibonacci numbers, commonly denoted as F(n), form a sequence called the Fibonacci Sequence. Each number in the Fibonacci series is the sum of the two preceding ones, starting from 0 and 1. The formula to compute the sequence is as follows:
The slideshow below illustrates the concept:
From a coding perspective, an iterative approach to solving the Fibonacci sequence is given below:
int main(){int num = 8;int element1 = 0, element2 = 1, next = 0;for (int i = 1 ; i < num ; i++ ){if ( i <= 1 )next = i;else{next = element1 + element2;element1 = element2;element2 = next;}cout << "Adding " << element1 << " and " << next << " = " << element2+element1 << endl;}}
Free Resources