How to resolve the algorithm Evaluate binomial coefficients step by step in the ALGOL 68 programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Evaluate binomial coefficients step by step in the ALGOL 68 programming language

Table of Contents

Problem Statement

This programming task, is to calculate ANY binomial coefficient. However, it has to be able to output

(

5 3

)

{\displaystyle {\binom {5}{3}}}

,   which is   10. This formula is recommended:

See Also:

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Evaluate binomial coefficients step by step in the ALGOL 68 programming language

Source code in the algol programming language

PROC factorial = (INT n)INT:
(
        INT result;
 
        result := 1;
        FOR i  TO n DO
                result *:= i
        OD;
 
        result
);
 
PROC choose = (INT n, INT k)INT:
(
        INT result;

# Note: code can be optimised here as k < n #
        result := factorial(n) OVER (factorial(k) * factorial(n - k));
 
        result
);

test:(
        print((choose(5, 3), new line))
)

  

You may also check:How to resolve the algorithm Even or odd step by step in the Wren programming language
You may also check:How to resolve the algorithm Mutual recursion step by step in the Pascal programming language
You may also check:How to resolve the algorithm Number reversal game step by step in the SenseTalk programming language
You may also check:How to resolve the algorithm Include a file step by step in the Retro programming language
You may also check:How to resolve the algorithm Metaprogramming step by step in the Haskell programming language