Monday, 2 March 2015

C++ Program To Find Fibonacci Series

Problem :- Write A Program To Find Fibonacci Series

Logic :- For Print Fibonacci Series We Use Simple Method .As we know that Fibonacci Series is start with Zero (0) and next Element is One Then we add previous two element and print next element of Fibonacci Series .

Example :- Fibonacci Series is upto 10 Element is below 

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

Explanation :- Fibonacci Series start with Zero and next element is one then first we print 0 and 1.
Now add two previous element and print then next element is 0+1=1.
repeat that process 
1+1=2
1+2=3
2+3=5
3+5=8
5+8=13
8+13=21
13+21=34

Done.

Solution :-

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

  cout<<"Enter The Number \n\n";
  cin>>n;
 
cout<<"\nFibonacci Series Is \n\n";
  cout<<a<<" "<<b<<" ";
 
for(i=0;i<n;i++)
  {
  c=a+b;
  cout<<c<<" ";
  a=b;
  b=c;
  }
cout<<"\n";
  return 0;

}

Output:-

C++ Program To Find Fibonacci Series

2 comments:
Write comments

Recommended Posts × +