C++ Program to Print Fibonacci Series

Write a c++ program to generate and print fibonacci series upto a given number, upto 1000. This C++ Program displays fibonacci Series upto 1000. First two numbers in the Fibonacci Series are always 0 and 1, reamaining numbers are obtained by adding previous two numbers in the series.

Formula to find nth term in fibonacci series:
F[n] = F[n-1] + F[n-2]

C++ program to display fibonacci series

/* Fibonacci series upto 1000 numbers in C++ */

#include<iostream>
using namespace std;
 
int main()
{
    int an0 = 0, an1 = 1, an2 = 1;
 
    cout << "Fibonacci Series:" << endl;
    cout << an1 << " " << an1 << " ";

    while (an0 + an1 < 1000)
    {
        an2 = an0 + an1;
        an0 = an1;
        an1 = an2;
        cout << an2 << " ";
    }
    cout << endl;
    return 0;
}

Output:

Fibonacci Series: 
1 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987