How to resolve the algorithm Multifactorial step by step in the FreeBASIC programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Multifactorial step by step in the FreeBASIC 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 FreeBASIC programming language
Source code in the freebasic programming language
' FB 1.05.0 Win64
Function multiFactorial (n As UInteger, degree As Integer) As UInteger
If n < 2 Then Return 1
Var result = n
For i As Integer = n - degree To 2 Step -degree
result *= i
Next
Return result
End Function
For degree As Integer = 1 To 5
Print "Degree"; degree; " => ";
For n As Integer = 1 To 10
Print multiFactorial(n, degree); " ";
Next n
Print
Next degree
Print
Print "Press any key to quit"
Sleep
You may also check:How to resolve the algorithm Nth root step by step in the COBOL programming language
You may also check:How to resolve the algorithm Assertions step by step in the Aime programming language
You may also check:How to resolve the algorithm Ormiston triples step by step in the Pascal programming language
You may also check:How to resolve the algorithm Zeckendorf number representation step by step in the Haskell programming language
You may also check:How to resolve the algorithm Multiplication tables step by step in the Excel programming language