RosettaCodeData/Task/Multifactorial/Modula-2/multifactorial.mod2
2026-04-30 12:34:36 -04:00

38 lines
667 B
Text

MODULE Multifactorial;
FROM STextIO IMPORT
WriteLn, WriteString;
FROM SWholeIO IMPORT
WriteInt;
VAR
Degree, N: INTEGER;
PROCEDURE MultiFactorial(N, Degree: INTEGER): INTEGER;
VAR
Result, I: INTEGER;
BEGIN
IF (N < 2) THEN
RETURN 1
ELSE
Result := N;
I := N - Degree;
WHILE I >= 2 DO
Result := Result * I;
I := I - Degree
END;
RETURN Result
END
END MultiFactorial;
BEGIN
FOR Degree := 1 TO 5 DO
WriteString("Degree ");
WriteInt(Degree, 1);
WriteString(" =>");
FOR N := 1 TO 10 DO
WriteString(" ");
WriteInt(MultiFactorial(N, Degree), 1);
END;
WriteLn;
END;
END Multifactorial.