Write a program to print Fibonacci series of n terms where n is input by user

0 1 1 2 3 5 8 13 24 .....

Source Code

#include<iostream>
using namespace std;


int main()
{
	int f=0,s=1,t,n;
 
	cout<<"Enter Number of terms of Series : ";
	cin>>n;
 
	cout<<f<<" "<<s<<" ";
 
	for(int i=3;i<=n;i++)
	{
		t=f+s;
		cout<<t<<" ";
		f=s;
		s=t;
	}
 
	
	return 0;
}


Output

Enter Number of terms of Series : 10
0 1 1 2 3 5 8 13 21 34