SCE

Create a C++ program that displays the first 10 Fibonacci numbers (1, 1, 2, 3, 5, 8, 13, 21, 34, and 55). Notice that, beginning with the third number in the series, each Fibonacci number is the sum of the prior two numbers. In other words, 2 is the sum of 1 plus 1, 3 is the sum of 1 plus 2, 5 is the sum of 2 plus 3, and so on.

Here is the Solution to the problem above:

#include <iostream> using namespace std; int fib(int n); int main(int argc, char *argv[]) { for (int x = 1; x <= 10; x++) { cout<<fib(x)<<" "; } cout<<endl; } int fib(int n) { if (n <= 1) return n; return fib(n-1) + fib(n-2); }