Differences
This shows you the differences between two versions of the page.
amdelf_uppg12 [2016-11-21 15:09] Anders Mosshäll |
amdelf_uppg12 [2022-07-18 13:20] |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Lösningsförslag - Uppgift 12 ====== | ||
- | <code php> | ||
- | |||
- | <?php | ||
- | include(' | ||
- | |||
- | $arr = array (41, 5, 26, 2, 88, 9, 38, 67, 14, 30, 25, 44, 11, 94, 58); | ||
- | |||
- | sort($arr); // Sortera för att skriva ut kombinationerna i storleksordning | ||
- | |||
- | $x = 0; | ||
- | while ($x < count($arr)){ | ||
- | $y = $x + 1; // Testa alla tal efter position $x | ||
- | while ($y < count($arr)){ | ||
- | $z = $y + 1; // Testa alla tal efter position $y | ||
- | while ($z < count($arr)){ | ||
- | | ||
- | if ($arr[$x] + $arr[$y] + $arr[$z] == 97){ // Summan 97? | ||
- | echo $arr[$x] . ' + ' .$arr[$y] . ' + ' . $arr[$z] .' = 97<br />'; | ||
- | } | ||
- | | ||
- | $z++; | ||
- | } | ||
- | $y++; | ||
- | } | ||
- | $x++; | ||
- | } | ||
- | |||
- | |||
- | include(' | ||
- | ?> | ||
- | |||
- | </ | ||
- | |||