Advertisement
ridjis

množenje matrica

Nov 27th, 2013
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. MODULE matmno;
  2. FROM InOut IMPORT WriteInt, ReadInt, WriteString, WriteLn;
  3. CONST   dim1=5;
  4.     dim2=4;
  5.     dim3=3;
  6. TYPE    mat1= ARRAY [1..dim1], [1..dim2] OF INTEGER;
  7.     mat2= ARRAY [1..dim2], [1..dim3] OF INTEGER;
  8.     mat3= ARRAY [1..dim1], [1..dim3] OF INTEGER;
  9. VAR A: mat1; B: mat2; C: mat3;
  10.     i: [1..dim1]; j: [1..dim2]; k: [1..dim3];
  11. BEGIN
  12.     WriteString('Unos prve matrice: ');
  13.     WriteLn;
  14.     FOR i:=1 TO dim1 DO
  15.         WriteString('Unesite ');
  16.         WriteInt(i,1);
  17.         WriteString('. vrstu, ');
  18.         FOR j:=1 TO dim2 DO
  19.                 WriteInt(j,1);
  20.                 WriteString('. kolonu: ');
  21.                 ReadInt(A[i,j]);
  22.         END;
  23.     END;
  24.     WriteLn;
  25.     WriteString('Unos druge matrice: ');
  26.     WriteLn;
  27.     FOR j:=1 TO dim2 DO
  28.         WriteString('Unesite ');
  29.         WriteInt(j,1);
  30.         WriteString('. vrstu, ');
  31.         FOR k:=1 TO dim3 DO
  32.                 WriteInt(k,1);
  33.                 WriteString('. kolonu: ');
  34.                 ReadInt(B[j,k]);
  35.         END;
  36.     END;
  37.    
  38.     FOR i:=1 TO dim1 DO
  39.         FOR k:=1 TO dim3 DO
  40.         C[i,k]:=0;
  41.             FOR j:=1 TO dim2 DO
  42.                 C[i,k] := C[i,k] + A[i,j] * B[j,k];
  43.             END;
  44.         END;
  45.     END;
  46.     WriteString('Proizvod dvije matrice iznosi: ');
  47.     WriteLn;
  48.     FOR i:=1 TO dim1 DO
  49.         WriteLn;
  50.         FOR k:=1 TO dim3 DO
  51.             WriteInt(C[i,k],5);
  52.         END;
  53.     END;
  54. END matmno.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement