// fibonacci.cc
// Iterative and recursive algorithms for computing Fibonacci numbers

// Standard C++ header files
#include <iostream>

// Forward definitions of auxiliary functions
long recFibonacci(long n);
long iterFibonacci(long n);

int main()
{
  long number;
  while(true) {
    cout << "Please enter a positive number (or negative to end): ";
    cin >> number;
    if (number < 0) return 0;
    cout << "Recursive: F(" << number << ") = " 
	 << recFibonacci(number) << endl;
    cout << "Iterative: F(" << number << ") = " 
	 << iterFibonacci(number) << endl;
  }
}

// Auxiliary Functions
long recFibonacci(long n)
{
  if (n==0) {
    return 0;
  }
  else if (n==1) {
    return 1;
  }
  else {
    return (recFibonacci(n-1) + recFibonacci(n-2));
  }
}


long iterFibonacci(long n)
{
  if (n==0) {
    return 0;
  }
  else if (n==1) {
    return 1;
  }
  long F0 = 0;
  long F1 = 1;
  long FN;
  for (long i=1; i<n; i++) {
    FN = F0 + F1; F0 = F1; F1 = FN;
  }
  return FN;
}





