Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Program carremag;
- Uses Wincrt;
- Type
- mat = Array [1..14,1..14] Of Byte ;
- Var
- N : Integer ;
- M : mat;
- Procedure saisie (Var n:Integer);
- Begin
- Repeat
- Writeln ('n=');
- Readln(n);
- Until (n In [1..14]) And (n Mod 2 <>0);
- End;
- Procedure zero (Var m:mat ;n:Integer);
- Var
- i,j: Integer;
- Begin
- For i:=1 To n Do
- For j:=1 To n Do
- m[i,j] := 0;
- End;
- Procedure affiche (n:Integer;m:mat);
- Var
- i,j: Integer;
- Begin
- For i:=1 To n Do
- Begin
- For j:=1 To n Do
- Write (m[i,j]:4);
- Writeln;
- End ;
- Writeln;
- End;
- Procedure remp (N : Integer ; Var m : mat );
- Var
- i,j,l,c,h: Integer ;
- Begin
- j := (n Div 2)+ 1 ;
- i := 1;
- l := i;
- c := j;
- For h:=1 To n*n Do
- Begin
- If m[i,j]=0 Then
- begin
- l:=i;
- c:=j;
- end
- Else
- begin
- i:=l+1;
- j:=c;
- if i<1 then
- i:=i-n;
- end;
- m[i,j] := h;
- i:= i-1;
- if i<1 then
- i:=n;
- j:= j+1;
- if j>n then
- j:=1;
- End;
- End;
- {
- • first you gonna start from (2,3)
- • second you gonna move one to the left and one down
- • 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
- then you are gonna go back to the pervious slot and move down by two
- • if you get out of the matrix then you come back from the other side
- }
- Begin
- saisie (n);
- zero (m,n);
- affiche(n,m);
- remp (n,m);
- affiche(n,m);
- End.
Add Comment
Please, Sign In to add comment