巴斯卡三角形

时间:2021-01-31 11:13:16

 

算法分析:

详情参考:

http://blog.csdn.net/yxstars/article/details/8664955


算法实现:


<span style="font-family:Microsoft YaHei;font-size:18px;"><?PHP
function basika($n,$r){
       $p = 1;
       for($i = 1;$i < $r; $i++){
              $p = $p *($n-$i+1)/$i;
       }
       return $p;
}
function paint(){
       for($n = 0; $n <= 12; $n++){
              for($r = 0; $r <=$n; $r ++){
                     if($r == 0){
                            for($i= 0; $i <=(12-$n);$i++){
                                   echo" ";
                            }
                     }else{
                            echo" ";
                     }
                      
                     echobasika($n,$r);
              }
              echo"</br>";
       }
}
paint();</span>