Catalan Numbers - Php

Print catalan numbers in php

Snippet Code


  
Rate this page :
  [ 0 votes]

To print catalan numbers series like 1,1, 2, 5, 14, 42, 132, 429, 1430, 4862, 16796,etc.. in php

<?php $n=10; $cat = 1; for($i=0;$i<=$n;$i++) { $a=1; $b=1; for($j=1;$j<=$i;$j++) $a*=$j; for($k=1;$k<=2*$i;$k++) $b*=$k; $CatNumber=$b/(($a*$a)*($i+1)); echo $CatNumber.","; } ?>

Tags


Ask Questions

Ask Question