**Fibonacci Series in C++:**

The series in which next number is always the sum of previous two numbers for example 0, 1, 1, 2, 3, 5, 8, 13, 21 etc. Fabonacci series always start with 0,1 then we add later numbers so first two numbers of fabonacci series will be 0,1

Fibonacci program can be written with and without recursion.

**Fibonacci series without recursion in C++**

- #include <iostream>
- using namespace std;
- int main() {
- int a=0, b=1, c , i, input;
- cout<<“Please Enter the Length of series “;
- cin>>input;
- cout<<a<<” “<<b<<” “; //printing 0 and 1
- for(i=2;i<input;++i) //loop starts from 2 because 0 and 1 are already printed
- {
- c=a+b;
- cout<<c<<” “;
- a=b;
- b=c;
- }
- return 0;
- }

**Fibonnaci series using recursion in C++**

- #include<iostream>
- using namespace std;
- void printFibonacci(int n){
- static int a=0, b=1, c;
- if(n>0){
- c = a + b;
- a = b;
- b = c;
- cout<<c<<” “;
- printFibonacci(n-1);
- }
- }
- int main(){
- int n;
- cout<<“Enter the number of elements: “;
- cin>>n;
- cout<<“Fibonacci Series: “;
- cout<<“0 “<<“1 “;
- printFibonacci(n-2); //n-2 because 2 numbers are already printed
- return 0;
- }