MartinGeorgiev

Pascal Triangle

Jun 5th, 2019
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. <?php
  2. $end = intval(readline());
  3. $n=1;
  4. $line=array(1,1);
  5. $tempLine=array();
  6. while($n<=$end){
  7. if ($n == 1){
  8. echo 1 . PHP_EOL;
  9. $n++;
  10. continue;
  11. }
  12. if ($n==2){
  13. echo "1 1" . PHP_EOL;
  14. $n++;
  15. continue;
  16. }
  17. else {
  18. for ($i=0;$i<$n;$i++){
  19. if ($i==0){
  20. array_push($tempLine,$line[$i]+0);
  21. continue;
  22. }
  23. if($i==$n-1){
  24. array_push($tempLine,$line[$i-1]+0);
  25. continue;
  26. }
  27. array_push($tempLine,$line[$i]+$line[$i-1]);
  28.  
  29. }
  30. echo join(" ",$tempLine);
  31. echo PHP_EOL;
  32. $line=array();
  33. $line=$tempLine;
  34. $tempLine=array();
  35. $n++;
  36. }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment