How to resolve the algorithm Multifactorial step by step in the PL/I programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Multifactorial step by step in the PL/I programming language
Table of Contents
Problem Statement
The factorial of a number, written as
n !
{\displaystyle n!}
, is defined as
n !
n ( n − 1 ) ( n − 2 ) . . . ( 2 ) ( 1 )
{\displaystyle n!=n(n-1)(n-2)...(2)(1)}
. Multifactorials generalize factorials as follows: In all cases, the terms in the products are positive integers. If we define the degree of the multifactorial as the difference in successive terms that are multiplied together for a multifactorial (the number of exclamation marks), then the task is twofold:
Note: The wikipedia entry on multifactorials gives a different formula. This task uses the Wolfram mathworld definition.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Multifactorial step by step in the PL/I programming language
Source code in the pl/i programming language
multi: procedure options (main); /* 29 October 2013 */
declare (i, j, n) fixed binary;
declare text character (6) static initial ('n!!!!!');
do i = 1 to 5;
put skip edit (substr(text, 1, i+1), '=' ) (A, COLUMN(8));
do n = 1 to 10;
put edit ( trim( multifactorial(n,i) ) ) (X(1), A);
end;
end;
multifactorial: procedure (n, j) returns (fixed(15));
declare (n, j) fixed binary;
declare f fixed (15), m fixed(15);
f, m = n;
do while (m > j); f = f * (m-fixed(j)); m = m - j; end;
return (f);
end multifactorial;
end multi;
You may also check:How to resolve the algorithm String prepend step by step in the Elena programming language
You may also check:How to resolve the algorithm Sorting algorithms/Strand sort step by step in the Go programming language
You may also check:How to resolve the algorithm Department numbers step by step in the Forth programming language
You may also check:How to resolve the algorithm User input/Text step by step in the REBOL programming language
You may also check:How to resolve the algorithm Rename a file step by step in the Slate programming language