How to resolve the algorithm Catalan numbers/Pascal's triangle step by step in the M2000 Interpreter 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 M2000 Interpreter 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 M2000 Interpreter programming language
Source code in the m2000 programming language
Module CatalanNumbers {
Def Integer count, t_row, size=31
Dim triangle(1 to size, 1 to size)
\\ call sub
pascal_triangle(size, &triangle())
Print "The first 15 Catalan numbers are"
count = 1% : t_row = 2%
Do {
Print Format$("{0:0:-3}:{1:0:-15}", count, triangle(t_row, t_row) - triangle(t_row +1, t_row -1))
t_row++
count++
} Until count > 15
End
Sub pascal_triangle(rows As Integer, &Pas_tri())
Local x=0%, y=0%
For x = 1 To rows
Pas_tri( 1%, x ) = 1@
Pas_tri( x, 1% ) = 1@
Next x
if rows<2 then exit sub
For x = 2 To rows-1
For y = 2 To rows + 1 - x
Pas_tri(x, y) = pas_tri(x - 1 , y) + pas_tri(x, y - 1)
Next y
Next x
End Sub
}
CatalanNumbers
You may also check:How to resolve the algorithm MD4 step by step in the D programming language
You may also check:How to resolve the algorithm Factorial step by step in the AmigaE programming language
You may also check:How to resolve the algorithm Loops/Do-while step by step in the Julia programming language
You may also check:How to resolve the algorithm Arithmetic evaluation step by step in the Jsish programming language
You may also check:How to resolve the algorithm Julia set step by step in the Rust programming language