114. PHP Program to Print Number triangle.
How does this program work?
- This program is used to print Number Triangle using PHP.
Here is the code
<html>
<head>
<title>PHP Program To print Triangle Pattern</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
function fact($num)
{
$f = 1;
for($i=1; $i<=$num; $i++)
$f = $f * $i;
return $f;
}
if(isset($_POST['submit']))
{
$n = $_POST['num'];
for ($i=0; $i<$n; $i++)
{
for($j=$n; $j>$i; $j-- )
{
echo(" \n");
echo " ";
}
for($j=0; $j<=$i; $j++)
{
$ans = (fact($i))/(fact($j)*fact($i-$j))." ";
echo $ans;
echo " ";
}
echo "</br>";
}
return 0;
}
?>
</body>
</html>