Vydělávej až 160.000 Kč měsíčně! Akreditované rekvalifikační kurzy s garancí práce od 0 Kč. Více informací.
Hledáme nové posily do ITnetwork týmu. Podívej se na volné pozice a přidej se do nejagilnější firmy na trhu - Více informací.
Avatar
Pulecek
Člen
Avatar
Pulecek:21.6.2016 19:23

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:in­teger;
matA,matB,matC:mat; //matice jsou typu mat(tedy dvourozmerna pole)
scitani,nasobe­ni: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('Vysle­dek:');

if scitani=true then
begin
for i:=1 to mA do
begin
for j:=1 to nA do
begin
matC[i,j]:=ma­tA[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]:=mat­C[i,j]+matA[i,k]*mat­B[k,j];
end;
writeln ('matC [ ',i,' , ',j,' ] := ',matC[i,j]:6:2);
end;
end;
end;

readln;
end.

 
Odpovědět
21.6.2016 19:23
Avatar
Martin Dráb
Tvůrce
Avatar
Martin Dráb:21.6.2016 21:47

Ahoj,

pravděpodobně po tobě chce něco jako toto:

For I := 1 To PocetRadku Do
  begin
  For J := 1 To PocetSloupcu Do
    Write(Matice[I, J]:5);

  Writeln;
  end;
Nahoru Odpovědět
21.6.2016 21:47
2 + 2 = 5 for extremely large values of 2
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.

Zobrazeno 2 zpráv z 2.