Example, according to Yang Hui's triangle "each number is equal to the sum of the left and right numbers in the previous row".
-
-
//Error message - error_reporting(e_all & ~e_deprecated & ~e_notice);
-
- //Print Yang Hui triangle function
- function yanghui($iline)
- {
- $a = array();
- $nb = '';
- for ($i = 0;$i <= $iline;$i++)//line
- {
- for ($j = 0;$j < ;= $i;$j++)//Column
- {
- if ($i == $j || $j == 0)//Row = column (that is, the last column) or the first row and the first column
- {
- $a[$i][$j] = 1;
- }
- else
- {
- $a[$i][$j] = $a[$i-1][$j]+$a[$ i-1][$j-1];//The value of the row + column = the addition of the two values of the previous row
- }
- } // bbs.it-home.org
- }
- return $a;
- } < /p>
//Print Yang Hui triangle
- $adata = yanghui(4);
- echo '
'; </li>
<li>print_r($adata); </li>
<li>echo ' ';
- ? >
-
Copy code
|