Write a program, which receives a number – n, and prints a triangle from 1 to n as in the examples.
Examples:
This is my solution:
<?php $number = readline(); for ($i = 1; $i <= $number; $i++) { for ($n = 1; $n <= $i; $n++) { echo $i . " "; } echo PHP_EOL; }
Mine:
<?php $end = intval(readline()); for ($row = 1; $row <= $end; $row++) { for ($col = 0; $col <= $row; $col++) { echo "$row "; } echo PHP_EOL; }
622 questions
979 answers
129 comments
53 users