How to resolve the algorithm Catalan numbers/Pascal's triangle step by step in the OCaml 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 OCaml 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 OCaml programming language
Source code in the ocaml programming language
let catalan : int ref = ref 0 in
Printf.printf "%d ," 1 ;
for i = 2 to 9 do
let nm : int ref = ref 1 in
let den : int ref = ref 1 in
for k = 2 to i do
nm := (!nm)*(i+k);
den := (!den)*k;
catalan := (!nm)/(!den) ;
done;
print_int (!catalan); print_string "," ;
done;;
You may also check:How to resolve the algorithm Successive prime differences step by step in the Arturo programming language
You may also check:How to resolve the algorithm Apply a callback to an array step by step in the REXX programming language
You may also check:How to resolve the algorithm Successive prime differences step by step in the ALGOL 68 programming language
You may also check:How to resolve the algorithm Real constants and functions step by step in the Lingo programming language
You may also check:How to resolve the algorithm Stem-and-leaf plot step by step in the Kotlin programming language