Program to Print Fibonacci Series

To print Fibonacci series in C++ programming, you have to ask from the user to enter total number of terms that he/she want to print fibonacci series upto the required number.

Now to print fibonacci series, first print the starting two number of the Fibonacci series and make a while loop to start printing the next number of the Fibonacci series. Use the three variable say a, b and c. Place b in a and c in b then place a+b in c to print the value of c to make and print Fibonacci series as shown here in the following program.

C++ Programming Code to Print Fibonacci Series

Following C++ program ask to the user to enter the limit upto which he/she want to print the Fibonacci series:

 

 

#include <iostream>

using namespace std;

int main()
{

//
int a=0, b=1, c=0, limit;
cout<<"Upto How many term ? ";

//
cin>>limit;
cout<<"Fabonacci Series : "<<a<<" "<<b<<" "; // first two term
c=a+b;
limit=limit-2; // decrease the limit by 2. since two numbers already printed
while(limit)
{
cout<<c<<" ";
a=b;
b=c;
c=a+b;
limit--;
}

}

 

xfer from :  https://codescracker.com/cpp/program/cpp-program-print-fabonacci-series.htm

posted @ 2019-05-22 16:29  Poission  阅读(131)  评论(0编辑  收藏  举报