Home >Backend Development >PHP Tutorial >PHP printing Yang Hui triangle graphic tutorial

PHP printing Yang Hui triangle graphic tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-07-25 09:12:581825browse

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


Statement:
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