Activity 5

Problem 1

Solution:

$st = "";
for ($i = 1; $i <= 5; $i++){
       $st .="*";
       echo $st . "<br>";
}

Output:
*
* *
* * *
* * * *
* * * * *

Problem 2

Solution:

$str = "";
for ($i = 1; $i <= 5; $i++)
       {
        $str .="*";
        echo $str . "<br>";
       }
for ($j = 5; $j >= 0; $j--)
       {
        echo $str ."<br>";
        $str = substr($str,1);
       }

Output:
*
* *
* * *
* * * *
* * * * *
* * * * *
* * * *
* * *
* *
*


Problem 3

Solution:

//Create form to accept user input and pass it to the php script
//PHP script:
$res;
$hi = $_GET['hrb'];
for ($i = 1; $i <= $hi; $i++)
       {
        $res += $i;
       }

if(isset($hi))
       {
        echo "Sum between 1 and $hi is: " . $res ;
       }
else{echo "
No inputs yet. Input range and click submit";}

Output:
Link to demo

Problem 4

Solution:

$rows=10;
$culomns=10;
echo "<table border='1'>";
for ($i = 1; $i <= $rows; $i++)
       {
        echo "<tr>";
        for($j = 1; $j <= $culomns; $j++)
        {
        echo "<td border='1'>" . $i * $j . "</td>";
        }
        echo "</tr>";
} echo "</table>";

Output:
12345678910
2468101214161820
36912151821242730
481216202428323640
5101520253035404550
6121824303642485460
7142128354249566370
8162432404856647280
9182736455463728190
102030405060708090100