ArfIsAToe

NotMyCode2.0

Jan 14th, 2021 (edited)
203
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Program carremag;
  2. Uses Wincrt;
  3. Type
  4.   mat = Array [1..14,1..14] Of Byte ;
  5. Var
  6.   N : Integer ;
  7.   M : mat;
  8.  
  9. Procedure saisie (Var n:Integer);
  10. Begin
  11.   Repeat
  12.     Writeln ('n=');
  13.     Readln(n);
  14.   Until (n In [1..14]) And (n Mod 2 <>0);
  15. End;
  16.  
  17. Procedure zero (Var m:mat ;n:Integer);
  18. Var
  19.   i,j: Integer;
  20. Begin
  21.   For i:=1 To n Do
  22.     For j:=1 To n Do
  23.       m[i,j] := 0;
  24. End;
  25.  
  26. Procedure affiche (n:Integer;m:mat);
  27. Var
  28.   i,j: Integer;
  29. Begin
  30.   For i:=1 To n Do
  31.     Begin
  32.       For j:=1 To n Do
  33.         Write (m[i,j]:4);
  34.  
  35.       Writeln;
  36.     End ;
  37.  
  38.   Writeln;
  39. End;
  40.  
  41. Procedure remp (N : Integer ; Var m : mat );
  42. Var
  43.   i,j,l,c,h: Integer ;
  44. Begin
  45.   j := (n Div 2)+ 1 ;
  46.   i := 1;
  47.   l := i;
  48.   c := j;
  49.   For h:=1 To n*n Do
  50.     Begin
  51.       If m[i,j]=0 Then
  52.                 begin
  53.                     l:=i;
  54.                     c:=j;
  55.                 end
  56.       Else
  57.         begin
  58.                  i:=l+1;
  59.                  j:=c;
  60.                  if i<1 then
  61.                     i:=i-n;
  62.                 end;
  63.             m[i,j] := h;
  64.             i:=  i-1;
  65.              if i<1 then
  66.                 i:=n;
  67.             j:=  j+1;
  68.                 if j>n then
  69.                     j:=1;
  70.     End;
  71. End;
  72. {
  73. • first you gonna start from (2,3)
  74. • second you gonna move one to the left and one down
  75. • if the slot is empty you gonna fill it with the value you have as your counter that you applied in your loop IF NOT
  76. then you are gonna go back to the pervious slot and move down by two
  77. • if you get out of the matrix then you come back from the other side
  78.  
  79.  
  80. }
  81. Begin
  82.   saisie (n);
  83.   zero (m,n);
  84.   affiche(n,m);
  85.   remp (n,m);
  86.   affiche(n,m);
  87. End.
  88.  
RAW Paste Data