Matrice vers Tableau

Poster un nouveau sujet   Répondre au sujet

Voir le sujet précédent Voir le sujet suivant Aller en bas

Matrice vers Tableau

Message par nabiL le Ven 28 Mar - 9:23

Quel est l'algorithme qui transforme cette matrice en ce tableau




*******

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

nabiL
Admin
Admin

Sexe:Masculin
Messages : 1972
Inscrit le : 19 Mar 2007
Localisation : Tunisie

Feuille de personnage
Capacité linguistique:
999/1000  (999/1000)

Revenir en haut Aller en bas

Re: Matrice vers Tableau

Message par manianis le Ven 28 Mar - 21:11

Vous avez dèjà posté cet exercice Nabil à ce que je pense.

manianis
Admin
Admin

Sexe:Masculin
Messages : 976
Inscrit le : 10 Oct 2007
Localisation : Tunisie

Feuille de personnage
Capacité linguistique:
999/1000  (999/1000)

Revenir en haut Aller en bas

Re: Matrice vers Tableau

Message par manianis le Ven 28 Mar - 23:19

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
Admin

Sexe:Masculin
Messages : 976
Inscrit le : 10 Oct 2007
Localisation : Tunisie

Feuille de personnage
Capacité linguistique:
999/1000  (999/1000)

Revenir en haut Aller en bas

Voir le sujet précédent Voir le sujet suivant Revenir en haut


Permission de ce forum:
Vous ne pouvez pas répondre aux sujets dans ce forum