LOVEGUN

Matrice magique

Oct 31st, 2020 (edited)
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 1.69 KB | None | 0 0
  1. Program exercice2;
  2. Uses Wincrt;
  3. Type
  4.   tab = Array [1..99,1..99] Of Integer;
  5.   tab2 = Array [1..99] Of Integer;
  6. Var
  7.   t: tab;
  8.   n: Integer;
  9. Procedure remplir (Var t:tab;Var n:Integer);
  10. Var
  11.   i,j: Integer;
  12. Begin
  13.   Repeat
  14.     Write ('Saisir N: ');
  15.     Readln (n);
  16.   Until (n Mod 2<>0);
  17.   For i:=1 To n Do
  18.     For j:=1 To n Do
  19.       Begin
  20.         Write ('T[',i,',',j,'] : ');
  21.         Readln (t[i,j]);
  22.       End;
  23. End;
  24.  
  25. Procedure ligne (t:tab;n:Integer;Var l:tab2);
  26. Var
  27.   i,j,x: Integer;
  28. Begin
  29.   For i:=1 To n Do
  30.     Begin
  31.       x := 0;
  32.       For j:=1 To n Do
  33.         x := x+t[i,j];
  34.       l[i] := x;
  35.     End;
  36. End;
  37.  
  38. Procedure colone (t:tab;n:Integer;Var c:tab2);
  39. Var
  40.   i,j,x: Integer;
  41. Begin
  42.   For i:=1 To n Do
  43.     Begin
  44.       x := 0;
  45.       For j:=1 To n Do
  46.         x := x+t[j,i];
  47.       c[i] := x;
  48.     End;
  49. End;
  50.  
  51. Function vligne (l:tab2;n:Integer): Boolean;
  52. Var
  53.   i: Integer;
  54.   test: Boolean;
  55. Begin
  56.   i := 0;
  57.   Repeat
  58.     i := i+1;
  59.     test := l[i]=l[i+1];
  60.   Until (test=False) Or (i=n-1);
  61.   vligne := test;
  62. End;
  63. Procedure diago (t:tab;n:Integer;Var d:tab2);
  64. Var
  65.   i,j,x: Integer;
  66. Begin
  67.   j := 0;
  68.     x := 0;
  69.     For i:=1 To n Do
  70.     Begin
  71.       j := j+1;
  72.       x := x+t[i,j];
  73.       d[1] := x;
  74.     End;
  75.   j := n;
  76.     x := 0;
  77.     For i:=n DownTo 1 Do
  78.     Begin
  79.       x := x+t[i,j];
  80.             j := j-1;
  81.     End;
  82.         d[2] := x;
  83. End;
  84.  
  85. Procedure matrice (t:tab;n:Integer);
  86. Var
  87.   l,c,d: tab2;
  88.   i: Integer;
  89.   test: Boolean;
  90. Begin
  91.   ligne (t,n,L);
  92.   colone (t,n,c);
  93.   diago (t,n,d);
  94.     test:=false;
  95.     if d[1]=d[2] Then
  96.     test:=True;
  97.   If vligne(L,n) And vligne(c,n) and test Then
  98.     Writeln ('La matrice est magique');
  99. End;
  100. Begin
  101.   remplir (T,n);
  102.   matrice (T,n);
  103. End.
  104.  
Add Comment
Please, Sign In to add comment