Dremendo Tag Line

Print the fibonacci number series 1 1 2 3 5 using while loop in C++

while Loop - Question 7

In this question, we will see how to print the fibonacci number series 1 1 2 3 5 8... up to 10th term in C++ programming using while loop. To know more about while loop click on the while loop lesson.

Q7) Write a program in C++ to print the fibonacci number series given below using while loop.

1 1 2 3 5 8... up to 10th term

Program

#include <iostream>
#include <conio.h>

using namespace std;

int main()
{
    int i=1,n1=1,n2=0,n3;

    while(i<=10)
    {
        n3=n1+n2;
        cout<<n3<<" ";
        n1=n2;
        n2=n3;

        i=i+1;
    }
    return 0;
}

Output

1 1 2 3 5 8 13 21 34 55
video-poster