[Challenge] - Pascal's Triangle
Posted: Sun Jul 31, 2016 8:48 am
[[ split from viewtopic.php?f=1&t=112782 --requinix ]]
Hi Apollo,
PLease help.
I tried your code below:
When I run it in the browser, the pascal triangle runs correctly but there's an error which says:
Undefined index: n in D:\wamp\www\exer\pascaltriangle.php on line 2 Call Stack
Can anyone solve this error? THanks in advance
Hi Apollo,
PLease help.
I tried your code below:
Code: Select all
<?php
$n = $_POST['n'];
if (!$n) die("<form method='post'>How many? <input type='text' name='n'> <input type='submit'></form>");
print("<table>");
$e = "<td> </td>";
for ($i=0; $i<=$n; $i++)
{
$row = array();
$row[] = 1;
$s = str_repeat($e,$n-$i);
print("<tr>$s");
for ($j=0; $j<$i; $j++)
{
if ($j)
{
$row[] = $prev[$j-1]+$prev[$j];
print($e);
}
print("<td>$row[$j]</td>");
}
$row[] = 0;
$prev = $row;
print("$s</tr>");
}
print("</table>");
?>Undefined index: n in D:\wamp\www\exer\pascaltriangle.php on line 2 Call Stack
Can anyone solve this error? THanks in advance