How to resolve the algorithm Catalan numbers/Pascal's triangle step by step in the ALGOL W programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Catalan numbers/Pascal's triangle step by step in the ALGOL W programming language

Table of Contents

Problem Statement

Print out the first   15   Catalan numbers by extracting them from Pascal's triangle.

Pascal's triangle

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Catalan numbers/Pascal's triangle step by step in the ALGOL W programming language

Source code in the algol programming language

begin
    % print the first 15 Catalan numbers from Pascal's triangle %
    integer n;
    n := 15;
    begin
        integer array pascalLine ( 1 :: n + 1 );
        % the Catalan numbers are the differences between the middle and middle - 1 numbers of the odd %
        % lines of Pascal's triangle (lines with 3 or more numbers)                                    %
        % note - we only need to calculate the left side of the triangle                               %
        pascalLine( 1 ) := 1;
        for c := 2 until n + 1 do begin
            % even line %
            for i := c - 1 step -1 until 2 do pascalLine( i ) := pascalLine( i - 1 ) + pascalLine( i );
            pascalLine( c ) := pascalLine( c - 1 );
            % odd line %
            for i := c     step -1 until 2 do pascalLine( i ) := pascalLine( i - 1 ) + pascalLine( i );
            writeon( i_w := 1, s_w := 0, " ", pascalLine( c ) - pascalLine( c - 1 ) )
        end for_c
    end
end.

  

You may also check:How to resolve the algorithm Integer overflow step by step in the Arturo programming language
You may also check:How to resolve the algorithm Accumulator factory step by step in the ooRexx programming language
You may also check:How to resolve the algorithm 100 doors step by step in the TI-83 BASIC programming language
You may also check:How to resolve the algorithm Minimum positive multiple in base 10 using only 0 and 1 step by step in the Haskell programming language
You may also check:How to resolve the algorithm Pisano period step by step in the Julia programming language