How to resolve the algorithm Multifactorial step by step in the Ada programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Multifactorial step by step in the Ada 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 Ada programming language
Source code in the ada programming language
with Ada.Text_IO; use Ada.Text_IO;
procedure Mfact is
function MultiFact (num : Natural; deg : Positive) return Natural is
Result, N : Integer := num;
begin
if N = 0 then return 1; end if;
loop
N := N - deg; exit when N <= 0; Result := Result * N;
end loop; return Result;
end MultiFact;
begin
for deg in 1..5 loop
Put("Degree"& Integer'Image(deg) &":");
for num in 1..10 loop Put(Integer'Image(MultiFact(num,deg))); end loop;
New_line;
end loop;
end Mfact;
You may also check:How to resolve the algorithm Circles of given radius through two points step by step in the Mathematica/Wolfram Language programming language
You may also check:How to resolve the algorithm Stack step by step in the Ring programming language
You may also check:How to resolve the algorithm Multiple distinct objects step by step in the M2000 Interpreter programming language
You may also check:How to resolve the algorithm Digital root step by step in the DCL programming language
You may also check:How to resolve the algorithm History variables step by step in the REXX programming language