home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / progm / m2t-2.zip / ANSWERS / CH04E3A.MOD < prev    next >
Text File  |  1989-01-18  |  826b  |  42 lines

  1.                             (* Chapter 4 - Programming exercise 3 *)
  2. MODULE CH04E3A;
  3.  
  4. FROM InOut IMPORT WriteString, WriteCard, WriteLn;
  5.  
  6. VAR Factorial : CARDINAL;
  7.     Count1    : CARDINAL;
  8.     Count2    : CARDINAL;
  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.       WriteCard(Count1,3);
  19.       WriteString(" is");
  20.       WriteCard(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. The factorial of  8 is 40320
  39.  
  40. *)
  41.  
  42.