Program For Fibonacci Series in C++

An arrangement wherein each number is the aggregate of going before two numbers is called Fibonacci arrangement.

For instance: 0 1 2 3 5 8 13 . . . . .

The following is the program to discover fibonacci arrangement in C++.

#include<iostream>
 
using namespace std;
 
int main()
{
	long n,first=0,second=1,third;
	cout<<"How many numbers?";
	cin>>n;
	cout<<"Fibonacci series\n"<<first<<" "<<second;
 
	for(int i=2;i<n;++i)
	{
		third=first+second;
		cout<<" "<<third;
		first=second;
		second=third;
	}
 
	return 0;
}

Output

How many numbers?5

Fibonacci series

0 1 1 2 3

Leave a Comment

error: Alert: Content is protected!!