settingsAccountsettings
By using our mini forum, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy
Menusettings

Q: Triangle of Numbers - PHP Task

+2 votes

Write a program, which receives a number – n, and prints a triangle from 1 to n as in the examples.

Examples:

php task triangle of numbers

asked in PHP category by user andrew

2 Answers

+1 vote

This is my solution:

<?php
$number = readline();

for ($i = 1; $i <= $number; $i++) {
    for ($n = 1; $n <= $i; $n++) {
        echo $i . " ";
    }
    echo PHP_EOL;
}
answered by user icabe
0 votes

Mine:

<?php
$end = intval(readline());

for ($row = 1; $row <= $end; $row++) {
    for ($col = 0; $col <= $row; $col++) {
        echo "$row ";
    }
    echo PHP_EOL;
}
answered by user hues
...