Fibonacci Sequence Generator Using Array C++

By | July 11, 2019

Task: Fibonacci Sequence Generator Using Array – C++ Program

The Source Code for Fibonacci Sequence Generator Using Array

// Write a C++ program to input number of terms
// of FIBONACCI Series required, then
// display Fibonacci Terms using Array
// Author: www.EasyCodeBook.com (c)
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
	//write program to generate FIBONACII series upto n terms using array
	int arr[100],i,n;
	cout<<"Enter Number of Fibonacci Terms required:";
	cin>>n;
	// Since first two terms are 0,1
	arr[0]=0;
	arr[1]=1;
	// use for loop to find remaining terms 
	for(i=2;i<n;i++)
	  arr[i]=arr[i-1]+arr[i-2];
	
	cout<<"Required "<<n<<" Fibonaccii Terms are:"<<endl;
	for (i=0;i<n;i++)
	cout<<arr[i]<<", ";

	return 0;
}

Out put of the sample run of Fibonacci Terms using Array C++ Program

Enter Number of Fibonacci Terms required:10
Required 10 Fibonaccii Terms are:
0, 1, 1, 2, 3, 5, 8, 13, 21, 34,
--------------------------------
Process exited after 55.6 seconds with return value 0
Press any key to continue . . .

Loading

Leave a Reply

Your email address will not be published. Required fields are marked *