Newer
Older
zweic / tests / 1 / t1.zwei
@glproj03 glproj03 on 20 Nov 2005 266 bytes *** empty log message ***
  1. class Factorial {
  2. // Solution itérative
  3. def factorial1 (x : Int ): Int = {
  4. var p : Int = 1;
  5. while (x > 0 ) {
  6. set p = p * x;
  7. set x = x - 1;
  8. }
  9. p
  10. };
  11. // Solution récursive
  12. def factorial2 (x : Int ): Int =
  13. if (x == 0 ) 1
  14. else x * this.factorial2 (x - 1 );
  15. }