Can you imagine creating a multiplication table like on the output below without using iteration? I know it’s cumbersome and will take lots of your effort and time. A multiplication table program will use two (2) iterations to display rows and columns. The first loop will specify the multiplicand which is from 1 to 10 and the second loop will specify the multiplier which is from 1 to 10 also.
PHP CODE FOR MULTIPLICATION TABLE
<html>
<body>
<table>
<?php
for($multiplicand=1;$multiplicand<=10;$multiplicand++)
{
echo "<tr>";
for($multiplier=1;$multiplier<=10;$multiplier++)
{
echo "<td>$multiplier X $multiplicand = ".$multiplicand*$multiplier."</td>";
}
echo "<tr>";
}
?>
</table>
</body></html>
The code above will display a multiplication from 1 to 10 like in the sample output below. Hope this helps! Good day! ^_^
No comments:
Post a Comment