How to resolve the algorithm Multifactorial step by step in the Rust programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Multifactorial step by step in the Rust 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 Rust programming language
Source code in the rust programming language
fn multifactorial(n: i32, deg: i32) -> i32 {
if n < 1 {
1
} else {
n * multifactorial(n - deg, deg)
}
}
fn main() {
for i in 1..6 {
for j in 1..11 {
print!("{} ", multifactorial(j, i));
}
println!("");
}
}
You may also check:How to resolve the algorithm Isqrt (integer square root) of X step by step in the EasyLang programming language
You may also check:How to resolve the algorithm Terminal control/Ringing the terminal bell step by step in the bc programming language
You may also check:How to resolve the algorithm Enforced immutability step by step in the Logtalk programming language
You may also check:How to resolve the algorithm RSA code step by step in the Julia programming language
You may also check:How to resolve the algorithm Pascal matrix generation step by step in the APL programming language