Monday, 2 March 2015

C++ Program For Fibonacci Series With Examples

Problem:- Write A C++ Program To Find Fibonacci Series Or C++ Program For Print Fibonacci Series Or C++ Program For Fibonacci Series With Examples.

Logic:- For Print Fibonacci Series We Use Simple Method. As we know that Fibonacci Series is started with Zero (0) and next Element is One Then we add previous two elements and print next element of Fibonacci Series.This process repeats up to n times, suppose you want to print a Fibonacci series up to 5 terms then you need to repeat this process up to 5 times and so on. 

Explanation:- Fibonacci Series start with Zero and next element is one then first we print 0 and 1. Now add two previous elements and print then next element is 0+1=1. repeat the process again and again until you get your answer.
0+1=1
1+1=2
1+2=3
2+3=5
3+5=8
5+8=13
8+13=21
13+21=34. . . . 

Done.

Fibonacci Series:- In mathematics, the Fibonacci numbers are the numbers in the following integer sequence, called the Fibonacci sequence, and characterized by the fact that every number after the first two is the sum of the two preceding ones.

Fibonacci Series :- 1 ,1 ,2 ,3 ,5 ,8 ,13 ,21 ,34.

Often, especially in modern usage, the sequence is extended by one more initial term.

Fibonacci Series :- 0 ,1 ,1 ,2 ,3 ,5 ,8 ,13 ,21 ,34.

The Fibonacci numbers occur in the sums of "shallow" diagonals in Pascal's triangle see in the given picture
Write A C++ Program To Find Fibonacci Series Or C++ Program For Print Fibonacci Series.


source=wikipedia

Important Fact about Fibonacci Series:- 'The 'Golden Ratio' or Phi' of any two consequent numbers of the sequence in Fibonacci Series is 1.618 or 1.6 (approx) Except starting 4 terms. 

Example:- The first 21 Fibonacci numbers Fn for n = 0, 1, 2, …, 20 are given below.

Fibonacci Series :- 0 ,1 ,1 ,2 ,3 ,5 ,8 ,13 ,21 ,34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765.

3 / 2             = 1.500
5 / 3             = 1.667
8 / 5             = 1.600
13 / 8           = 1.625
21 / 13         = 1.615
34 / 21         = 1.619
55 / 34         = 1.617
89 / 55         = 1.618
144 / 89       = 1.618
233 / 144     = 1.618
377 / 233     = 1.618
610 / 377     = 1.618
987 / 610     = 1.618
1597 / 987   = 1.618
2584 / 1597 = 1.618
4181 / 2584 = 1.618
6765 / 4181 = 1.618

Solution:-

#include<iostream>
using namespace std;
int main()
{
  int a=0,b=1,i,n,c;

  cout<<"Enter The Number \n\n"; //Enter the number of terms
  cin>>n;
  
  cout<<"\nFibonacci Series Is \n\n"; //Fibonacci Series Is given below
  cout<<a<<" "<<b<<" ";
  
 for(i=0;i<n;i++)
  {
    c=a+b;           //here adding two previous value
    cout<<c<<" ";
    a=b;              //swap the value
    b=c;              //here first two value result stored in 'b'
   }                     //Loop end.
 cout<<"\n";
  return 0;

}

Output:-

C++ Program To Find Fibonacci Series


You May Also Like:-

1. C Program to Display Fibonacci Series Using While Loop.

2. C++ Program To Find Large Fibonacci Series.

3. C Program to Display Fibonacci Series Using While Loop.

4. C++ Program To Fibonacci Series Using Functions.
Ghanendra Yadav
Ghanendra Yadav

I Am Ghanendra Yadav Owner Of This Website. I Love Programming, Web Developing, Logo Making, Banner And Website designing. Currently I Am Studying In NIT Warangal And Also Working With WSDC( As Web Application Developer ) In NIT Warangal For Any Query Mail Me I Will Answer Within 24 Hours Email:- yghanendra@student.nitw.ac.in

Find me on Social Media

Facebook | Twitter | Google+ | RSS Feed

3 comments: