杨辉三角

Posted 不二小杰

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了杨辉三角相关的知识,希望对你有一定的参考价值。

哦。。曾经的痛。。。。

<?php 

$arr = [1];
for ($i=0; $i < 10 ; $i++) {
    
    for ($j=0; $j < count($arr); $j++) { 
        echo $arr[$j];
        echo " ";
    }
    echo "<br>";
    $arr = getNext($arr);
}

function getNext($pre)
{
    array_push($pre, 0);
    array_unshift($pre, 0);
    $next = [];
    for ($i=0; $i < count($pre)-1; $i++) { 
        $next[] = $pre[$i] + $pre[$i+1];
    }
    return $next;
}

 

以上是关于杨辉三角的主要内容,如果未能解决你的问题,请参考以下文章