I got bored so i did a simple php program that generates a centered triangle with table for every spaces and stars. I used a 4 for loops.
First for loops is for the size of the triangle
Second for loops is for the spaces at the left side.
Third for loop is for the stars.
Fourth for loop is for the spaces at the right side.
<?php
$size = 5;
echo "<table border = '1'> <tr>";
for ($i = 0; $i < $size; $i++)
{
$stars = 1 + 2 * ($i);
$space = $size - $i;
for ($j = 0; $j < $space; $j++)
{
echo("<td> </td>");
}
for ($k = 0; $k < $stars; $k++)
{
echo "<td>*</td>";
}
$stars = 1 + 2 * ($i);
$space = $size - $i;
for ($j = 0; $j < $space; $j++)
{
echo("<td> </td>");
}
echo("</tr>");
}
echo("</table>")
?>
0 comments:
Post a Comment