Differences

This shows you the differences between two versions of the page.

Link to this comparison view

amdelf_uppg12 [2017-09-01 14:54]
amdelf_uppg12 [2022-07-18 13:20] (current)
Line 1: Line 1:
 +====== Lösningsförslag - Uppgift 12 ======
 +<code php>
 +
 +<?php
 +include('head.php');                  
 +
 +$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)){   // Loopa igenom arrayen
 +  $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('foot.php');
 +?>
 +
 +</code>
 +