How to resolve the algorithm Multifactorial step by step in the ALGOL W programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Multifactorial step by step in the ALGOL W 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 ALGOL W programming language

Source code in the algol programming language

begin
    % returns the multifactorial of n with the specified degree %
    integer procedure multifactorial ( integer value n, degree ) ;
        begin
            integer mf, v;
            mf := v := n;
            while begin
                      v := v - degree;
                      v > 1
            end do mf := mf * v;
            mf
        end multifactorial ;

    % tests as per task %
    for degree := 1 until 5 do begin
        i_w := 1; s_w := 0; % output formatting %
        write( "Degree: ", degree, ":" );
        for v := 1 until 10 do begin
            writeon( " ", multifactorial( v, degree ) )
        end for_v
    end for_degree
end.

  

You may also check:How to resolve the algorithm Function definition step by step in the Ecstasy programming language
You may also check:How to resolve the algorithm Calendar - for REAL programmers step by step in the Lua programming language
You may also check:How to resolve the algorithm Rendezvous step by step in the Nim programming language
You may also check:How to resolve the algorithm Fractal tree step by step in the Tcl programming language
You may also check:How to resolve the algorithm Memory allocation step by step in the Oforth programming language