public class Fact {
  public static int factIter(int n) {
    int f = 1;
    for (int i=1; i<=n; i++) {
      f = f*i;
      System.out.println("f="+f);
    }
    return f;
  }
  public static int factRec(int n) {
    if (n==0) return 1;
    int r = n*factRec(n-1);
    System.out.println(r);
    return r;
  }
  public static int factRecAcc(int n,int r) {
    System.out.println("factRecAcc("+n+","+r+")");
    if (n==0) {
      System.out.println("return "+r);
      return r;
    }
    int res = factRecAcc(n-1,n*r);
    System.out.println("return "+res);
    return res;
  }
  public static int factRecAccPropre(int n,int r) {
    if (n==0) return r;
    return factRecAcc(n-1,n*r);
  }
  public static int factRecAccPropreIter(int n,int r) {
    while (n!=0) {
      r = n*r;
      n = n-1;
    }
    return r;
    /*
      for (n>=0; n--) {
       r = n*r;
      }
    */
  }
  public static int factRecOriginelle(int n) {
    System.out.println("factRecOriginelle("+n+")");
    if (n==0) {
      System.out.println("return 1");
      return 1;
    }
    int r = n*factRecOriginelle(n-1);
    System.out.println("return "+r);
    return r;
  }
  public static void main(String []a) {
    //    System.out.println(factIter(10));
    System.out.println(factRecOriginelle(10));
    System.out.println(factRecAcc(10,1));
  }
}