/*/////////////////////////////////////////////////////////////////////////////
* A Fibonacci sequence is defined as follows:
The first and second terms in the sequence are 0 and 1.
Subsequent terms are found by adding the preceding two terms in the sequence.
Write a C++ program to generate the first n terms of the sequence.
* Shubham Kumar
* sshubhamk1@hotmail.com
/////////////////////////////////////////////////////////////////////////////*/
#include <iostream>
using namespace std;
int main(void)
{
int first = 0, second =1, n;
do
{
cout << "Enter the number of terms: ";
cin >> n;
if( n <= 0)
{
cout << "Number of terms should be positive(n>0). Try agian..."<<endl;
}
}while(n <= 0);
cout << "n terms of sequence are "<<endl;
cout << first << endl << second << endl;
for(int i = 0; i < n-2; i++)
{
int total = first + second;
cout << total << endl;
first = second;
second = total;
}
return 0;
}