How to resolve the algorithm Multifactorial step by step in the Icon and Unicon programming language

Published on 12 May 2024 09:40 PM

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

Source code in the icon programming language

procedure main(A)
    l := integer(A[1]) | 10
    every writeRow(n := !l, [: mf(!10,n) :])
end

procedure writeRow(n, r)
    writes(right(n,3),": ")
    every writes(right(!r,8)|"\n")
end

procedure mf(n, m)
    if n <= 0 then return 1
    return n*mf(n-m, m)
end


  

You may also check:How to resolve the algorithm Palindrome detection step by step in the Logo programming language
You may also check:How to resolve the algorithm Reverse words in a string step by step in the Raku programming language
You may also check:How to resolve the algorithm Tic-tac-toe step by step in the МК-61/52 programming language
You may also check:How to resolve the algorithm Loops/Increment loop index within loop body step by step in the REXX programming language
You may also check:How to resolve the algorithm Vector step by step in the 11l programming language