Stránka: 1 z 1
| [ Príspevkov: 3 ] | |
Autor | Správa |
---|
Registrovaný: 07.04.10 Prihlásený: 11.11.19 Príspevky: 6 Témy: 3 | 3 |
Kód: program nasobenie_matic; uses crt; var m1,m2,m3: array [1..12,1..12] of integer; k,l,f,m,i,j,t,z :integer; {k,l,f,m - velkost matic} y :integer; {suradnice graf. kurzoru}
BEGIN clrscr; writeln('********* NASOBENIE MATIC *********');writeln; write('Zadaj velkost prvej matice: x '); gotoxy(30,3); read(k); gotoxy(34,3); read(l); write('Zadaj clenov 1. matice: '); writeln; y:=wherey; for i:=1 to k do writeln(#179:2,#179:l*4); {vykreslenie mriezky} for i:=1 to k do {vlozenie prvkov do matice} for j:=1 to l do begin gotoxy(4*j,i+4); read(m1[i,j]); end;
writeln; write('Zadaj velkost druhej matice: x '); {druha matica} y:=wherey; gotoxy(34,y);read(f); read(m); if l<>f then writeln('Nema riesenie') else write('Zadaj clenov 2. matice: '); writeln; y:=wherey; for i:=1 to f do writeln(#179:2,#179:m*4); {vykreslenie mriezky} for i:=1 to f do {vlozenie prvkov do matice} for j:=1 to m do begin gotoxy(4*j,y+i-1); read(m2[i,j]); end;
writeln; m3[1,1]:=0; {zaciatok algoritmu nasobenia matic} for i:=1 to k do for t:=1 to f do for j:=1 to l do for z:=1 to m do m3[i,t]:=(m3[i,t]+m1[i,j]*m2[m,t]);
writeln('Sucin matic je matica typu: ',k,' x ',m); y:=wherey; for i:=1 to k do writeln(#179:2); {vykreslenie mriezky} for i:=1 to k do {vypisanie vyslednej matice} begin for j:=1 to m do begin gotoxy(4*j,y+i-1); write(m3[i,j]); end; write(#179:2); end; readkey; END.
takze problem nasobenia matic som vyriesil. Lenze teraz mi ako vysledok z neznamych dovodov vychadzaju 6-nasobky povodnych vysledkov. proste vyplnim matice dvojkami a namiesto stvoriek mi vychadzaju 24, teda 6-nasobky. pri trojkach vychadzaju namiesto deviatok 54 atd. pls help mee
|
|
Registrovaný: 23.11.08 Príspevky: 187 Témy: 34 | 34 Bydlisko: IP: 209.85.... |
tu som nasiel program pre nasobenie matic, snad pomoze:
Kód: Program M; uses crt; const rozmer=2; type matica=array [1..rozmer,1..rozmer] of integer; var M1,M2,M3,M4:matica;
procedure GENEROVANIE (var M1:matica); var i,j,k,l:integer; begin write('Zadaj interval hodnot: -'); gotoxy(24,1); read(k); gotoxy(27,1); readln(l); clrscr; randomize; for i:=1 to rozmer do begin for j:=1 to rozmer do {M1[i,j]:=random(11)+10;{interval 10-20} M1[i,j]:=random(l-k+1)+k; end; writeln('Vygenerovana matica:'); for i:=1 to rozmer do begin for j:=1 to rozmer do write(M1[i,j]:3); writeln; end; end;
procedure GENEROVANIE2 (var M2:matica); var i,j:integer; begin for i:=1 to rozmer do begin for j:=1 to rozmer do if i=j then M2[i,j]:=i else M2[i,j]:=1; end; writeln('Vygenerovana matica2:'); for i:=1 to rozmer do begin for j:=1 to rozmer do write(M2[i,j]:2); writeln; end; end;
procedure NASOBENIE (M3:matica); var i,j,k,pom:integer; begin for i:=1 to rozmer do begin for j:=1 to rozmer do begin pom:=0; for k:=1 to rozmer do pom:=pom+(M1[i,k]*M2[k,j]); M3[i,j]:=pom; end; end; writeln('Nasobena matica:'); for i:=1 to rozmer do begin for j:=1 to rozmer do write(M3[i,j]:3); writeln; end; end;
procedure VYPIS (M1:matica); var i,j:integer; begin for i:=1 to rozmer do begin for j:=1 to rozmer do write(M1[i,j]:4); writeln; end; end;
procedure PREKLOPENIE_MATICE_PODLA_VEDLAJSEJ_DIAGONALY (var M4:matica); var i,j:integer; begin for j:=1 to rozmer do begin for i:=1 to rozmer do M4[i,j]:=M1[rozmer-j+1,rozmer-i+1]; end; writeln('Generovana matica preklopena podla vedlajsej diagonaly:'); for i:=1 to rozmer do begin for j:=1 to rozmer do write(M4[i,j]:4); writeln; end; end;
BEGIN clrscr; GENEROVANIE (M1); writeln; GENEROVANIE2 (M2); writeln; NASOBENIE (M3); writeln; PREKLOPENIE_MATICE_PODLA_VEDLAJSEJ_DIAGONALY (M4); readkey; END.
_________________ Tajna misia: Ignorovat dlzne a makcene. |
|
Registrovaný: 06.04.10 Prihlásený: 18.02.14 Príspevky: 47 Témy: 2 | 2 |
Kód: program nasobenie_matic; uses Crt; var m1,m2,m3: array [1..12,1..12] of Integer; k,l,f,m,i,j,y,h : Integer; {suradnice graf. kurzoru}
BEGIN ClrScr; WriteLn ('********* NASOBENIE MATIC *********'); WriteLn; Write ('Zadaj velkost prvej matice: x'); GotoXY (29,3); Read (k); GotoXY (33,3); Read (l); Write ('Zadaj clenov 1. matice: '); WriteLn; for i:=1 to k do WriteLn (#179:2,#179:l*4); {vykreslenie mriezky} for i:=1 to k do {vlozenie prvkov do matice} for j:=1 to l do begin GotoXY (4*j,i+4); Read (m1[i,j]); end; WriteLn; y:=wherey; Write ('Zadaj velkost druhej matice: x'); {druha matica} GotoXY (30,y); Read (f); GotoXY (34,y); Read (m); if l<>f then WriteLn ('Nema riesenie') else Write ('Zadaj clenov 2. matice: '); WriteLn; y:=wherey; for i:=1 to f do WriteLn (#179:2,#179:m*4); {vykreslenie mriezky} for i:=1 to f do {vlozenie prvkov do matice} for j:=1 to m do begin GotoXY (4*j,y+i-1); Read (m2[i,j]); end; WriteLn; for h:=1 to m do for i:=1 to k do for j:=1 to l do m3[h,i]:=m3[h,i] + m1[h,j]*m2[j,i]; {algoritmus} WriteLn ('Sucin matic je matica typu: ',k,' x ',m); y:=wherey; for i:=1 to k do WriteLn (#179:2); {vykreslenie mriezky} for i:=1 to k do begin {vypisanie vyslednej matice} for j:=1 to m do begin GotoXY (4*j,y+i-1); Write (m3[i,j]); end; Write (#179:2); end; Read; END.
Mal si tam jeden cyklus navyse
|
|
Stránka: 1 z 1
| [ Príspevkov: 3 ] | |
Podobné témy | Témy | Odpovede | Zobrazenia | Posledný príspevok |
---|
| v Novinky | 1 | 2979 | 06.02.2006 13:35 Teddy | | v Assembler, C, C++, Pascal, Java | 3 | 598 | 23.02.2008 9:59 Aries | | v Grafické programy | 0 | 451 | 15.11.2011 11:34 gabika | | v Ponuka práce | 4 | 1129 | 03.04.2009 22:05 bbeni | | v Assembler, C, C++, Pascal, Java | 4 | 1157 | 11.01.2009 17:49 programator | | v Assembler, C, C++, Pascal, Java | 0 | 550 | 24.03.2011 19:42 roxor | | v Assembler, C, C++, Pascal, Java | 5 | 748 | 13.08.2008 6:42 imcold | | v Assembler, C, C++, Pascal, Java | 1 | 2006 | 17.05.2007 8:52 p360t | | v Assembler, C, C++, Pascal, Java | 3 | 952 | 19.07.2007 22:33 imcold | | v Assembler, C, C++, Pascal, Java | 2 | 539 | 23.11.2011 13:25 jojinkho | | v Assembler, C, C++, Pascal, Java | 2 | 328 | 22.12.2012 15:36 lukac | | v Assembler, C, C++, Pascal, Java | 4 | 1810 | 27.02.2008 20:45 martin90 | | v Assembler, C, C++, Pascal, Java | 5 | 836 | 24.11.2007 11:10 scarletjohanson | | v Assembler, C, C++, Pascal, Java | 2 | 605 | 22.03.2011 16:16 Cleo | | v Assembler, C, C++, Pascal, Java | 0 | 542 | 12.05.2009 14:02 cod | | v Ostatné | 7 | 584 | 05.11.2018 21:07 kikuska222 |
|