PHP printing Yang Hui triangle graphic tutorial

WBOY
Release: 2016-07-25 09:12:58
Original
1776 people have browsed it

PHP prints Yang Hui's triangle as shown in the picture: PHP printing Yang Hui triangle graphic tutorial

Use PHP programming to generate any row of Yang Hui triangles.

  1. function yanghui($line)
  2. {
  3. echo "";
  4. for($i=1;$i {
  5. echo "
  6. ";
  7. for($j=1;$j {
  8. $yh[$i][1]=1;
  9. if ($i==$j) $yh[$i][$j]=1;
  10. else $yh[$i][$j]=$yh[$i-1][$j-1]+$yh[$i-1][ $j];
  11. echo "
  12. ";
  13. }
  14. echo "
  15. ";
  16. }
  17. echo "
  18. ";
  19. echo $yh[$i][$j];
  20. echo "
  21. ";
  22. }
Copy code


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template