How to resolve the algorithm Multifactorial step by step in the CLU programming language

Published on 12 May 2024 09:40 PM

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

Source code in the clu programming language

multifactorial = proc (n, degree: int) returns (int)
    result: int := 1
    for i: int in int$from_to_by(n, 1, -degree) do
        result := result * i
    end
    return (result)
end multifactorial

start_up = proc ()
    po: stream := stream$primary_output()
    for n: int in int$from_to(1, 10) do
        for d: int in int$from_to(1, 5) do
            stream$putright(po, int$unparse(multifactorial(n,d)), 10)
        end
        stream$putc(po, '\n')
    end
end start_up

  

You may also check:How to resolve the algorithm Non-decimal radices/Input step by step in the Erlang programming language
You may also check:How to resolve the algorithm Shell one-liner step by step in the Erlang programming language
You may also check:How to resolve the algorithm Sorting algorithms/Bead sort step by step in the 360 Assembly programming language
You may also check:How to resolve the algorithm Binary strings step by step in the Nim programming language
You may also check:How to resolve the algorithm UTF-8 encode and decode step by step in the Action! programming language