Advertisement
Guest User

Untitled

a guest
Dec 6th, 2016
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.78 KB | None | 0 0
  1. <?php
  2.  
  3. $matrix1 = [];
  4. $matrix2 = [];
  5.  
  6. loadMatrix($matrix1);
  7. loadMatrix($matrix2);
  8.  
  9. $result = multiplyMatrix($matrix1, $matrix2);
  10.  
  11. loadMatrix($result);
  12.  
  13. function printMatrix($matrix)
  14. {
  15.     $matrix = [];
  16.        
  17.     for($i = 0; $i < 3; $i++)
  18.         for($j = 0; $j < 3; $j++)
  19.             echo $matrica[$i][$j]." ";
  20.     echo "\n";
  21. }
  22.  
  23. function loadMatrix(&$matrix)
  24. {
  25.     $matrix = [];
  26.        
  27.     for($i = 0; $i < 3; $i++)
  28.     {
  29.         for($j = 0; $j < 3; $j++)
  30.         {
  31.             $element = readline();
  32.             $matrix[$i][] = $element;
  33.         }
  34.     }
  35. }
  36.  
  37. function multiplyMatrix($matrix1, $matrix2)
  38. {
  39.     $matrix3 = [];
  40.  
  41.     for ($i = 0; $i < 3; $i++)
  42.     {
  43.         $matrix3[$i][] += $matrix1[$i][] * $matrix2[][$i];
  44.     }
  45.  
  46.     return matrix3;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement