Fibonacci Series in C++ (2 Methods)


 First we must know what Fibonacci series is.

0 1 1 2 3 5 8 13 21………..


By definition, the first Fibonacci number is ‘0’ and second Fibonacci number is ‘1’. Then each subsequent number is calculated based on sum of the previous two. Numbers of Fibonacci sequence are known as Fibonacci numbers.

This sequence has many applications in mathematics and Computer Science.


Here in the program we have two initial values of series, ‘0’ and ‘1’ in variables ‘first’ and ‘sec’ respectfully.

Then user enters the Fibonacci number in variable ‘n‘.

When n>2, the loop is executed, its value starts from 3 as two values are printed already.

In loop the sum of previous two numbers are stored in variable ‘sum’ then value of ‘sec’ is saved in ‘first’ and value of ‘sum’ is saved in ‘sec’, at last the value of sum is printed. Further the loop is continued until the value of ‘i’ reaches to the value of ‘n’.

Author Description


Our mission is to bring the affordable Technology education to people everywhere, in order to help them achieve their dreams and change the world. - Follow @program_guide

No comments yet.

Join the Conversation