// fact_iterative.c - iterative solution for fact calculation

#include <stdio.h>

unsigned fact(unsigned num);

//------------------------------------------------------------
int main()
{
  unsigned num = 0;

  printf("Please enter a positive number: ");
  scanf("%u",&num);
  printf("%u! is %u\n",num,fact(num));
  return(0);
}

//------------------------------------------------------------
unsigned fact(unsigned num)
{
  unsigned result = num;
  if (num <= 1) // attention! otherwise an underflow occurs
    return(num);
  while(--num)
    result *= num;
  return(result);
}
