/***************************************************************************
 *  Columbia University Introduction to Computer Programming in C COMS 1003
 *  A simple recursive factorial
 *
 *  Copyright (C) 2005 Michael E. Locasto
 *
 *  All rights reserved.
 *
 * $Id: fact.c,v 1.1 2005/10/01 21:49:04 locasto Exp $
 **************************************************************************/
#include <stdio.h>
#include <stdlib.h>

long fact(long);

long fact(long n)
{
   if(0==n || 1==n)
      return 1;
   else
      return n*fact(n-1);
}

/**
 * Calculate ./fact [n]
 */
int main(int argc, char* argv[])
{
   long result = 0L;
   long x = 0;

   if(argc==2)
   {
      x = (long)atoi(argv[1]);
      result = fact(x);
      printf("fact(%ld) = %15ld\n", x, result);
   }else{
      printf("Invalid args.\n");
      return -1;
   }
   return 0;
}
