Задача2 - PHP Online

Form of PHP Sandbox

Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php in the places where the PHP script should be executed.



Your result can be seen below.

Result of php executing





Full code of Задача2.php

  1. <?php
  2. $line = stream_get_line(STDIN, 1024, PHP_EOL);
  3. $d =  explode(' ', $line);
  4. $m = [];
  5. $max;
  6. $min;
  7.  
  8. for ($i=0; $i< count($d); $i++){
  9.     if($i%2 || $i = 0)
  10.      array_push ($m, $d[$i] );
  11. }
  12.  
  13. for ($i=0; $i< count($m); $i++)
  14. {
  15.     for ($j=$i+1; $j< count($m); $j++)   
  16.     {
  17.          if ($m[$i] > $m[$j]) 
  18.          
  19.          $max = $m[$i];}
  20. }
  21.          
  22.          for ($i=0; $i< count($m); $i++)
  23. {
  24.     for ($j=$i+1; $j< count($m); $j++)   
  25.     {
  26.          if ($m[$i] < $m[$j]) {
  27.          
  28.          $min = $m[$i];}
  29.              
  30.     }
  31.  
  32. for ($i=0; $i< count($m); $i++)
  33. {
  34.     $sum = $sum + $m[$i];
  35. }
  36.  
  37. echo $max;
  38. echo $min;
  39. echo $sum;
  40. }
  41. ?>
File Description
  • Задача2
  • PHP Code
  • 31 Aug-2022
  • 631 Bytes
You can Share it: