Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program Permutations;
- {$APPTYPE CONSOLE}
- {$R *.res}
- uses
- System.SysUtils;
- const
- n = 5; // Кол-во элементов массива
- type
- TArray = Array[1..n] of Integer;
- var
- A: TArray;
- i, j: Integer;
- f: Text;
- procedure FillArray(var A: TArray);
- var
- i: Integer;
- begin
- for i := 1 to n do
- A[i] := i;
- end;
- procedure Swap(var x, y: Integer);
- var
- temp: Integer;
- begin
- temp := x;
- x := y;
- y := temp;
- end;
- procedure Generate(var A: TArray; k: Integer);
- var
- i: Integer;
- str: String;
- begin
- if k = n then
- begin
- for i := 1 to n do
- begin
- str := IntToStr(A[i]) + ' ';
- Write(str);
- Write(f, str);
- end;
- Writeln;
- Writeln(f, '');
- end
- else
- for i := k + 1 to n do
- begin
- Swap(A[k + 1], A[i]);
- Generate(A, k + 1);
- Swap(A[k + 1], A[i]);
- end;
- end;
- begin
- Assign(f, 'info.txt');
- Rewrite(f);
- FillArray(A);
- Generate(A, 0);
- CloseFile(f);
- Readln;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement