Zdravim,
potreboval bych trochu poradit jak vytvorit tento program:
Program nacte z jednoho souboru prirozene cislo M, ctvercovou matici A typu M,N a tuto matici vytiskne. Dale pak vytiskne matici, ktera se od matice A lisi tim, ze ma prohozeny 1. radek s 1. sloupcem.
Fórum › Pascal
Program s matici

hrozne nudny tema..hrozne me nebavilo
ale podivej se na dvojrozmerny pole a cyklus FOR a zkus napsat vytvoreni a vypsani matice. to je jeste docela jednoduchy. az to budes mit tak to sem hod a s tim preklopenim ti pomuzu, mam to v sesite...
Tak sem dal dohromady nejak ten vypis...
Snad je to spon trochu dobre :-D
uses
SysUtils;
const Matica = 'matice.txt';
type Matice = array[1..100,1..100] of Integer;
SM = text;
var M,N : Matice;
Vstup : SM;
Rd,i,j,k : Integer;
begin
Assign (Vstup,Matica);
Reset (Vstup);
ReadLn (Vstup,Rd);
Write ('Zakladni matice');
writeln;
for i := 1 to Rd do
begin
for j := 1 to Rd do
begin
Read (Vstup,M[i,j]);
Write (M[i,j] : Rd)
end;
ReadLn (Vstup);
WriteLn;
end;
readln
end.
jelikoz to mas se souborama se kterejma se teprve zaciname ucit tak ti hodim jak sme to delali my:
procedure VYTVOR(M,N:integer; var A:DVOJPOLE);
var I,J:integer;
begin
for I:=1 to M do
for J:=1 to N do
readln(A[I,J]);
end;
procedure VYPIS(M,N:integer; A:DVOJPOLE);
var I,J:integer;
begin
for I:=1 to M do
begin
for J:=1 to N do
write(A[I,J],' ');
writeln;
end;
end;
melo by to fungovat ted du do sesitu najit to preklopeni..
procedure PREKLOPENI(M:integer; var A:DVOJPOLE);
var I,J,POM:integer;
begin
for I:=1 to M-1 do
for J:=I+1 to M do
begin
POM:=A[I,J];
A[I,J]:=A[J,I];
A[J,I]:=POM;
end;
end;
tohle by melo bejt ono, neni to odladeny takze si to uprav aby to slapalo s tim souborem a kdyztak napis kdyby neco neslapalo...
Jestli mas prohodit jenom prvni radek s prvnim sloupcem a nic jineho, tak ten for bude jenom jeden:
for i:=2 to rozmer_matice do begin prohod prvek na [1,i] s prvkem na [i,1]; end;
Smysl to samozrejme bude mit jenom pro ctvercovou matici, jinak by v radku prvky prebyvaly a ve sloupci chybely nebo naopak.
Od dvojky zacinam proto, ze prohazovat prvek v levem hornim rohu sam se sebou je zbytecne.
Moje stránka.

Přidej příspěvek
Ano, opravdu chci reagovat → zobrazí formulář pro přidání příspěvku
×Vložení zdrojáku
×Vložení obrázku
×Vložení videa
































Uživatelé prohlížející si toto vlákno
Podobná vlákna
Problém s maticí — založil Honzik
Maximum v matici — založil fja
Hledani v matici — založil slezikán
Vyhledávání v matici — založil Tonny
Třídění prvků v matici — založil Lontek
Moderátoři diskuze