#
# fact.jako
#
# Some simple code to print some factorials
#
# Based on fact.pasm originally be Leon Brocard <acme@astray.com> 2001-09-14.
#
# Copyright (C) 2001-2003 Gregor N. Purdy. All rights reserved.
# This program is free software. It is subject to the same
# license as the Parrot interpreter.
#
# $Id: fact.jako,v 1.4 2003/07/03 15:32:25 gregor Exp $
#

use sys;

const int N = 15;


#
# fact()
#

sub int fact(int n) {
  var int i =  0;
  var int f =  1;

  while(i <= n) {
    i++;
    f *= i;
  }

  return f;
}


#
# MAIN PROGRAM:
#

var int f;

sys::print("Algorithm F1 (The factorial function)\n");
sys::print("    Calculating fact($N) = ...\n");

f = fact(N);

sys::print("    ... = $f\n");

