home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / m / mod2tutr.zip / EXAMPLES.ZIP / CH04E3B.MOD < prev    next >
Text File  |  1989-01-18  |  817b  |  42 lines

  1.                             (* Chapter 4 - Programming exercise 3 *)
  2. MODULE CH04E3A;
  3.  
  4. FROM InOut IMPORT WriteString, WriteInt, WriteLn;
  5.  
  6. VAR Factorial : INTEGER;
  7.     Count1    : INTEGER;
  8.     Count2    : INTEGER;
  9.  
  10. BEGIN
  11.  
  12.    FOR Count1 := 1 TO 8 DO
  13.       Factorial := 1;
  14.       FOR Count2 := 1 TO Count1 DO
  15.          Factorial := Factorial * Count2;
  16.       END;
  17.       WriteString("The factorial of");
  18.       WriteInt(Count1,3);
  19.       WriteString(" is");
  20.       WriteInt(Factorial,6);
  21.       WriteLn;
  22.    END;
  23.  
  24. END CH04E3A.
  25.  
  26.  
  27.  
  28.  
  29. (* Result of execution
  30.  
  31. The factorial of  1 is     1
  32. The factorial of  2 is     2
  33. The factorial of  3 is     6
  34. The factorial of  4 is    24
  35. The factorial of  5 is   120
  36. The factorial of  6 is   720
  37. The factorial of  7 is  5040
  38. ------>  integer overflow
  39.  
  40. *)
  41.  
  42.