este es el ejercicio real por si no me entendieron
TRIANGLE PUZZLE
By starting at the top of the triangle and moving to adjacent numbers on the row below, the maximum total from top to bottom is 27..
5
9 6
4 6 8
0 7 1 5
I.e. 5 + 9 + 6 + 7 = 27.
Write a program in PHP to find the maximum total from top to bottom in the text file , a text file containing a triangle with 100 rows. What is the maximum sum for the triangle?????
Código PHP:
Ver original
<?php $i=0; $j=0; $x=0; $sum=0; $sum2=0; if($_POST['calcular']){ echo ("<br>"); for($i=1;$i<=4;$i++){ for($j=1;$j<=$i;$j++){ $vector[$j]=$x; $z=$vector[$j]; echo (" ". $z);} echo ("<br>"); } $c = 1; for($a=1;$a<=4;$a++){ if($a > 1){ if($vector[$c-1] > $vector[$c]){ $sum = $sum + $vector[$c-1]; } else { $sum = $sum + $vector[$c]; $c++; } } } echo ("la suma es ".$sum); } ?>