C++ Program to Display Fibonacci Series

In this program, you will learn how to display Fibonacci Series upto the user provided terms.

The Fibonacci Sequence is the series of numbers: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34. Here the next number is the sum of previous two numbers.



Source Code
#include<iostream>
using namespace std;

int main()
{
    int i, term;
    int first=0, second=1, next;

    cout<<"How many terms: ";
    cin>> term;
    cout<<"\nFibonacci series:\n";
    cout<< first << " " << second;
    for(i=2; i<term; i++)
    {
        next = first + second;
        cout<< next << ", ";
        first = second;
        second = next;
    }
    return 0;
}
Output
How many terms: 11

Fibonacci series:
0 11, 2, 3, 5, 8, 13, 21, 34, 55,