Matrice vers Tableau
Forum INFOMATH :: Enseignement de l'informatique :: Informatique - Collège & Lycée :: Exercices Pascal
Page 1 sur 1•
Matrice vers Tableau
Quel est l'algorithme qui transforme cette matrice en ce tableau

*******


*******

Nabil - tunis
خير الناس أنفعهم للناس
خير الناس أنفعهم للناس

nabiL- Admin


- Messages : 1908
Inscrit le : 19 Mar 2007
Localisation : Tunisie
Feuille de personnage
Capacité linguistique:


(999/1000)
Re: Matrice vers Tableau
Vous avez dèjà posté cet exercice Nabil à ce que je pense.
manianis- Admin


- Messages : 976
Inscrit le : 10 Oct 2007
Localisation : Tunisie
Feuille de personnage
Capacité linguistique:


(999/1000)
Re: Matrice vers Tableau
- Code:
program matrice_vers_tableau;
const
DIM = 5;
type
mat = array [0..DIM - 1, 0..DIM - 1] of char;
tab = array [0..DIM*DIM - 1] of char;
var
i, j, k : integer;
c : char;
inc_i, inc_j : integer;
m : mat;
t : tab;
begin
// initialiser la matrice
c := 'A';
for j:=0 to DIM-1 do begin
for i:=0 to DIM-1 do begin
m[j,i] := c;
c := succ(c);
end;
end;
// afficher la matrice
Writeln('matrice');
for j:=0 to DIM-1 do begin
for i:=0 to DIM-1 do begin
write(m[j,i],' ');
end;
writeln;
end;
// ranger la matrice dans le tableau
i := 0; j := 0;
inc_i := 1; inc_j := -1;
for k:=0 to DIM*DIM-1 do begin
t[k] := m[j, i];
i := i + inc_i;
j := j + inc_j;
(* descente *)
if (j < 0) or (i >= DIM) then begin
if (i >= DIM) then begin
i := DIM - 1;
j := j + 2;
end;
if (j < 0) then j := 0;
inc_i := -1;
inc_j := 1;
end;
(* montée *)
if (i < 0) or (j >= DIM) then begin
if (j >= DIM) then begin
j := DIM - 1;
i := i + 2;
end;
if (i < 0) then i := 0;
inc_j := -1;
inc_i := 1;
end;
end;
// afficher le résultat
Writeln('tableau');
for k:=0 to DIM*DIM-1 do
write(t[k], ' ');
readln;
end.
manianis- Admin


- Messages : 976
Inscrit le : 10 Oct 2007
Localisation : Tunisie
Feuille de personnage
Capacité linguistique:


(999/1000)






