#include<iostream> // header file
using namespace std;
main() // simple main function
{
//variable declaration
int number, firstvalue = 0, secondvalue = 1, next ;
// simple programming of cout
cout<<"Enter the number of terms:\a";
cin>>number;
cout<<"-------------------------------------\n"<<endl;
cout<<"Fabonacci series of "<<number<<"is:\n";
cout<<"-------------------------------------\n"<<endl;
for (int i=0;i<number;i++)
{
if(i<=1)
next = i;
else
{
next = firstvalue + secondvalue;
firstvalue = secondvalue;
secondvalue = next;
}
cout<<next<<"\t";
}
cout<<"\n\n \a";
}
// fb: programmarsarmy.blogspot.com
OutPut:
No comments:
Post a Comment