Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (*1.napisati program koji ucitava prirodan boroj n (n<20) i celobrojnu matricu nxn
- i proverava da li je matrica simetricna po glavnoj i sporednoj dijagonali*)
- MODULE dijag;
- FROM InOut IMPORT WriteString,ReadInt,WriteLn,ReadCard,WriteCard;
- TYPE MATRICA=ARRAY [1..20],[1..20] OF INTEGER;
- VAR n:CARDINAL;
- mat1: MATRICA;
- (*ucitavanje matrice*)
- PROCEDURE ucitaj(VAR mat1:MATRICA; n:CARDINAL);
- VAR i,j:CARDINAL;
- BEGIN
- WriteString('Unesite: ');
- WriteLn;
- FOR i:=1 TO n DO
- FOR j:=1 TO n DO
- WriteString('mat[');
- WriteCard(i,1);
- WriteString(',');
- WriteCard(j,1);
- WriteString('] = ');
- ReadInt(mat1[i,j] );
- END;
- END;
- END ucitaj;
- (*stampanje*)
- PROCEDURE stampaj(VAR mat1:MATRICA; n:CARDINAL);
- VAR i,j:CARDINAL;
- BEGIN
- WriteString('Matrica izgleda ovako: ');
- WriteLn;
- FOR i:=1 TO n DO
- FOR j:=1 TO n DO
- WriteCard(mat1[i,j],5);
- END;
- WriteLn;
- END;
- END stampaj;
- (*simetricnost glavna*)
- PROCEDURE simetricnost(VAR mat1:MATRICA) : BOOLEAN;
- VAR i,j:CARDINAL;
- BEGIN
- FOR i:=2 TO n DO
- FOR j:=1 TO i-1 DO
- IF mat1[i,j] # mat1[j,i] THEN
- RETURN FALSE;
- END;
- END;
- END;
- RETURN TRUE;
- END simetricnost;
- (*sporedna dijagonala*)
- PROCEDURE sporednadijag (VAR mat1:MATRICA) : BOOLEAN;
- VAR i,j:CARDINAL;
- BEGIN
- FOR i:=1 TO n-1 DO
- FOR j:=1 TO n-i DO
- IF mat1[i,j] # mat1[n+1-j,n+1-i] THEN
- RETURN FALSE;
- END;
- END;
- END;
- RETURN TRUE;
- END sporednadijag;
- (*glavni program*)
- BEGIN
- WriteString('Unesite dimenziju matrice: ');
- ReadCard(n);
- ucitaj(mat1,n);
- stampaj(mat1,n);
- WriteLn;
- (*glavna dijagonala*)
- IF simetricnost(mat1) THEN
- WriteString('Matrica je simetricna po glavnoj dijagonali.');
- ELSE
- WriteString('Matrica nije simetricna po glavnoj dijagonali.');
- END;
- WriteLn;
- (*sporedna dijagonala*)
- IF sporednadijag(mat1) THEN
- WriteString('Matrica je simetricna po sporednoj dijagonali.');
- ELSE
- WriteString('Matrica nije simetricna po sporednoj dijagonali.');
- END;
- END dijag.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement