89. PHP Program to Print Floyd's triangle.
How does this program work?
- This program is used to print print Floyd's triangle using PHP.
- In this program we are using for loop to print number triangle, number without reassigning.
Here is the code
<html>
<head>
<title>PHP Program To print Floyd's triangle</title>
</head>
<body>
<form method="post">
<table border="0">
<tr>
<td> <input type="text" name="num" value="" placeholder="Enter no.of rows"/> </td>
</tr>
<tr>
<td> <input type="submit" name="submit" value="Submit"/> </td>
</tr>
</table>
</form>
<?php
if(isset($_POST['submit']))
{
$n = $_POST['num'];
$number = 1;
for($i = 1; $i <= $n; $i++)
{
for($j = 1; $j <= $i; $j++)
{
echo $number ." ";
$number++;
}
echo "<br>";
}
return 0;
}
?>
</body>
</html>