/* fibo.cpp -- It prints out the first N Fibonacci numbers.
 */

#include <iostream>
#include <iomanip>
using namespace std;

// Print out the first n Fibonacci numbers. n is assumed to be >= 1.
void fibo ( int n )
{
    int current = 1;      // The value of the (i)th fibonacci number 
    int next    = 1;      // The value of the (i+1)th fibonacci number 

    cout << "\n\n\t  I \t Fibonacci(I) \n\t=====================" << endl;
    for ( int i = 1; i <= n; i++ ) {
	cout << "\t" << setw(3) << i <<  "\t\t" 
             << setw(4) << current << endl;
	int next2 = current + next;
	current = next;
	next    = next2;
     }
}

int main ( void ) 
{
    int n;        // The number of fibonacci numbers we will print 

    cout << "How many Fibonacci numbers do you want to compute? ";
    cin  >> n;
    if ( n <= 0 )
       cout << "The number should be positive." << endl;
    else 
       fibo ( n );

    return 0;
}

/* The output from a run of this program was:

How many Fibonacci numbers do you want to compute? 12

	  I 	 Fibonacci(I) 
	=====================
	  1		   1
	  2		   1
	  3		   2
	  4		   3
	  5		   5
	  6		   8
	  7		  13
	  8		  21
	  9		  34
	 10		  55
	 11		  89
	 12		 144

*/
