码迷,mamicode.com
首页 > 其他好文 > 详细

杨辉三角

时间:2017-08-19 12:44:08      阅读:90      评论:0      收藏:0      [点我收藏+]

标签:nbsp   style   ret   push   array   blog   php   get   turn   

哦。。曾经的痛。。。。

<?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;
}

 

杨辉三角

标签:nbsp   style   ret   push   array   blog   php   get   turn   

原文地址:http://www.cnblogs.com/buerr/p/7395938.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!