fork(10) download
  1. Program transpose_matrice;
  2. Const nmax=10;
  3. Type Mat=array[1..nmax,1..nmax] of integer;
  4. Var M:Mat;
  5. n:integer;
  6. (*****************************)
  7. Procedure saisie (Var n:integer);
  8. Begin
  9. Repeat
  10. Writeln('Donner n :');
  11. Readln(n);
  12. Until n in [1..nmax];
  13. End;
  14. (*********************)
  15. Procedure remplir (Var M:Mat; n:integer);
  16. Var i, j:integer;
  17. begin
  18. For i:=1 To n Do
  19. For j:=1 To n Do
  20. Begin
  21. Writeln('Donner M[',i,',',j,']');
  22. Readln(M[i,j]);
  23. End;
  24. End;
  25. (*******************************)
  26. Procedure Transpose (Var M:Mat;n:integer);
  27. Var aux,i,j:integer;
  28. Begin
  29. For i:=1 to n do
  30. For j:=1 to i-1 do
  31. Begin
  32. aux:=M[i,j];
  33. M[i,j]:=M[j,i];
  34. M[j,i]:=aux;
  35. End;
  36. End;
  37. (**************************)
  38. Procedure Affiche ( M:Mat; n:integer);
  39. Var i, j:integer;
  40. Begin
  41. For i:=1 to n do
  42. Begin
  43. For j:=1 to n do
  44. Write( M[i,j],' ');
  45. Writeln;
  46. End;
  47. End;
  48. {Programme Principal}
  49. Begin
  50. saisie (n);
  51. remplir (M, n);
  52. Transpose (M, n);
  53. Affiche (M, n);
  54. End.
Success #stdin #stdout 0s 288KB
stdin
3
1
2
3
4
5
6
7
8
9
stdout
Donner n :
Donner M[1,1]
Donner M[1,2]
Donner M[1,3]
Donner M[2,1]
Donner M[2,2]
Donner M[2,3]
Donner M[3,1]
Donner M[3,2]
Donner M[3,3]
1 4 7 
2 5 8 
3 6 9