{ *************************************************** }
{  Program to calculate the factorial of a number N,  }
{  illustrating the use of a loop                     } 
{ *************************************************** }

program factorial( input, output );
var 
  N, count, fact : integer;

begin
  { Get N from the user }
  write( 'N = ' ); readln(N);

  { Negative N is not allowed }
  if N < 0
  then 
    writeln( 'Cannot take the factorial of a negative number' )
  else
    begin
      fact := 1; count := 1;
      { Loop to calculate 1 * 2 * .. (N-1) * N }
      while count <= N do
	begin
	  fact := fact * count;
	  count := count + 1;
	end;
      writeln( 'Factorial ', N:1, ' = ', fact:1 );
    end; { N >= 0 }
end.
