#include <iostream>
using namespace std;

// Recursion handout for CPS171, by Victor R. Volkman (sysop@HAL9K.com)

int iSummation ( /* in */  int   n )		
{
  int sum=0;
  for (int i=0; i<=n; i++)
    sum += i;	
  return sum;
 }

int  rSummation ( /* in */  int   n )		
{
  if  ( n == 1)				//  base case
    return  1 ;
  else					// general case	
    return ( n + rSummation ( n - 1 ) ) ;
}


int iGcd(int v1, int v2)
{
  int temp;
  while (v2) {
    temp = v2;
    v2 = v1 % v2;
    v1 = temp;
    }
  return v1;
}

int rGcd(int v1, int v2)
{
  if (v2 == 0)
    return v1;   
  else
   return rGcd(v2, v1%v2);
}

int iFibonacci(int v)
{
    int temp, first =1, second=1;
    for(int k=0; k < v-1; k++)
    {
        temp = first + second;
        first = second;
        second = temp;
    }
    return second;
}

int rFibonacci(int n)
{ 
    if (n < 3)
      return n;
    else
      return( rFibonacci(n-2) + rFibonacci(n-1));
}


int main()
{
   cout << "Summation of 1..4 is " << iSummation(4) << endl;
   cout << "Summation of 1..4 is " << rSummation(4) << endl;
   cout << "Greatest common divisor of 15 and 123 is " << iGcd(15,123) << endl;
   cout << "Greatest common divisor of 15 and 123 is " << rGcd(15,123) << endl;
   cout << "Fibonacci of 10 is " << iFibonacci(10) << endl;
   cout << "Fibonacci of 10 is " << rFibonacci(10) << endl;
}
