top of page

Fibonacci series

  • Ben
  • Feb 26, 2018
  • 1 min read

#include <iostream>

using namespace std;

int main() { // Getting the input of fibonacci series long int n; cout<<"Enter the size of fibonacci series"<<endl; cin>>n; // Getting an array long int *arr = new long int[n]; // First two of fibonacci values are initialized arr[0]= 0; arr[1]= 1; // Fibonacci series for(int i=2;i<n;i++) { arr[i] = arr[i-1] + arr[i-2]; } //Printing Fibonacci series cout<< " The fibonacci series is"<<endl; for(int i=0;i<n;i++) { cout<< arr[i] <<" "; } return 0; }

 
 
 

Kommentare


bottom of page