Advertisement
ridjis

MnozenjeMatrica

Dec 4th, 2013
409
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. MODULE rz5;
  2. FROM InOut IMPORT WriteLn, WriteString, WriteCard, ReadCard;
  3. CONST dim= 10;
  4. TYPE mat1= ARRAY [1..dim],[1..dim] OF CARDINAL;
  5.      mat2= ARRAY [1..dim],[1..dim] OF CARDINAL;
  6.      mat3= ARRAY [1..dim],[1..dim] OF CARDINAL;
  7. VAR A: mat1; B: mat2; C: mat3;
  8.     i,j,k,dim1,dim2,dim3: CARDINAL;
  9. BEGIN
  10.   (*DIMENZIJA 1. MATRICE*)
  11.   WriteString('Unesite dimenziju kolone 1. matrice: ');
  12.   ReadCard(dim1);
  13.   WriteString('Unesite dimenziju vrste 1. matrice: ');
  14.   ReadCard(dim2);
  15.   (*UCITAVANJE PRVE MATRICE*)
  16.   WriteString('Unesite prvu matricu dimenzija ');
  17.   WriteCard(dim1,1);
  18.   WriteString('x');
  19.   WriteCard(dim2,1);
  20.   WriteString(': ');
  21.   WriteLn;
  22.   FOR i:=1 TO dim1 DO
  23.     FOR j:=1 TO dim2 DO
  24.       ReadCard(A[i,j]);
  25.     END;
  26.     WriteLn;
  27.   END;
  28.   (*DIMENZIJA 2. MATRICE*)
  29.   WriteString('Unesite dimenziju vrste 2. matrice: ');
  30.   ReadCard(dim3);
  31.   (*UCITAVANJE DRUGE MATRICE*)
  32.   WriteString('Unesite drugu matricu dimenzija ');
  33.   WriteCard(dim2,1);
  34.   WriteString('x');
  35.   WriteCard(dim3,1);
  36.   WriteString(': ');
  37.   WriteLn;
  38.   FOR j:=1 TO dim2 DO
  39.     FOR k:=1 TO dim3 DO
  40.       ReadCard(B[j,k]);
  41.     END;
  42.     WriteLn;
  43.   END;
  44.   (*STAMPANJE MATRICA*)
  45.   WriteString('+Prva matrica izgleda ovako+ ');
  46.   WriteLn;
  47.   FOR i:=1 TO dim1 DO
  48.     FOR j:=1 TO dim2 DO
  49.       WriteCard(A[i,j],5);
  50.     END;
  51.     WriteLn;
  52.   END;
  53.   WriteString('+Druga matrica izgleda ovako+ ');
  54.   WriteLn;
  55.   FOR j:=1 TO dim2 DO
  56.     FOR k:=1 TO dim3 DO
  57.       WriteCard(B[j,k],5);
  58.     END;
  59.     WriteLn;
  60.   END;
  61.   (* MNOZENjE MATRICA*)
  62.   FOR i:=1 TO dim1 DO
  63.     FOR k:=1 TO dim3 DO
  64.       C[i,k]:=0;
  65.       FOR j:=1 TO dim2 DO
  66.         C[i,k] := C[i,k] + A[i,j] * B[k,j];
  67.       END;
  68.     END;
  69.   END;
  70.   (*ISPIS PROIZVODA MATRICE*)
  71.   WriteString('+Proizvod matrica izgleda ovako+ ');
  72.   WriteLn;
  73.   FOR i:=1 TO dim1 DO
  74.     FOR k:=1 TO dim3 DO
  75.       WriteCard(C[i,k],5);
  76.     END;
  77.     WriteLn;
  78.   END;
  79. END rz5.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement