Zdravím prosila bych pomoc, mám mít do školy program, který má
počítat s maticemi. Program mi funguje ale matice se vypíše stylem, že se
napíše souřadnice [m,n]=6 .... a takhle do sloupečku a učitel po mě chce
aby to vypadalo opravdu jako matice a nevím jak to pořídit.
Kód vypadá takto:
Program Matice;
uses crt;
type mat = array [1..20,1..20] of real; //typ mat (matice) je dvourozmerne
pole realnych cisel
var mA,nA,mB,nB,i,j,k,vstup:integer;
matA,matB,matC:mat; //matice jsou typu mat(tedy dvourozmerna pole)
scitani,nasobeni:boolean;
begin
scitani:=false;
nasobeni:=false;
clrscr;
TextColor(12);
writeln('Vlozte cela cisla od 1 do 20'); writeln;
TextColor(15);
write('Pocet radku matice A : m = '); readln(mA);
write('Pocet sloupcu matice A : n = '); readln(nA); writeln;
write('Pocet radku matice B : m = '); readln(mB);
write('Pocet sloupcu matice B : n = '); readln(nB); writeln;
if (mA=mB) and (nA=nB) and (mA<>nA) then
begin
writeln ('Jedina mozna operace je scitani matic');
scitani := true;
end;
if ((mA<>mB) or (nA<>nB)) and (nA=mB) then
begin
writeln ('Jedina mozna operace je nasobeni matic');
nasobeni := true;
end;
if (mA=nA) and (nA=mB) and (mB=nB) then
begin
writeln ('Vyberte pozadovanou operaci:');
writeln ('1 - scitani matic');
writeln ('2 - nasobeni matic');
readln(vstup);
if vstup=1
then scitani:=true;
if vstup=2
then nasobeni:=true;
end;
writeln;
if scitani=true then
begin
writeln('Bude provedena operace scitani');
writeln('Vysledna matice bude typu (',mA,',',nA,')');
end;
if nasobeni=true then
begin
writeln('Bude provedena operace nasobeni');
writeln('Vysledna matice bude typu (',mA,',',nB,')');
end;
if (scitani=false) and (nasobeni=false) then writeln('Neni mozne proveset
operaci scitani ani nasobeni, program bude ukoncen');
writeln;
if (mA>20) or (nA>20) or (mB>20) or (nB>20) then
begin
TextColor(12);
write('Byla zadany hodnoty mimo rozsah programu !!');
readln;
exit;
end;
writeln('matice [radek,sloupec]');
for i:=1 to mA do
begin
for j:=1 to nA do
begin
write ('matA [ ',i,' , ',j,' ] := ');
readln(matA[i,j]);
end;
end;
writeln;
for i:=1 to mB do
begin
for j:=1 to nB do
begin
write ('matB [ ',i,' , ',j,' ] := ');
readln(matB[i,j]);
end;
end;
writeln;
writeln('Vysledek:');
if scitani=true then
begin
for i:=1 to mA do
begin
for j:=1 to nA do
begin
matC[i,j]:=matA[i,j]+matB[i,j];
writeln ('matC [ ',i,' , ',j,' ] := ',matC[i,j]:6:2);
end;
end;
end;
if nasobeni=true then
begin
for i:=1 to mA do
begin
for j:=1 to nB do
begin
matC[i,j]:=0;
for k:=1 to nA do
begin
matC[i,j]:=matC[i,j]+matA[i,k]*matB[k,j];
end;
writeln ('matC [ ',i,' , ',j,' ] := ',matC[i,j]:6:2);
end;
end;
end;
Děláme co je v našich silách, aby byly zdejší diskuze co nejkvalitnější. Proto do nich také mohou přispívat pouze registrovaní členové. Pro zapojení do diskuze se přihlas. Pokud ještě nemáš účet, zaregistruj se, je to zdarma.