Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program lab5;
- {$APPTYPE CONSOLE}
- uses
- SysUtils, Math;
- const m=4;
- type TM=array [1..m,1..m] of Integer;
- const p: TM=((6, -17, 92, 60),
- (30, 23, 0, -1),
- (-24, 75, 12, 12),
- (44, 3, 47, -19));
- Var A:array[1..1000] of array[1..1000] of Integer;
- i, j, max, i_max, j_max, n, way, x1, x2: Integer;
- begin
- n:=0;
- writeln('Enter the way to set the array: 1 - keyboard input, 2 - randomly, 3 - typed constant ');
- readln(way);
- while (way<>1) and (way<>2) and (way<>3) do
- begin
- write('Please enter only 1, 2 or 3: ');
- readln(way);
- end;
- if (way=1) or (way=2) then
- begin write('Enter the order of the matrix: ');
- readln(n);
- end;
- if (way=1) then //keyboard input
- begin
- writeln('Enter the elements of the array:');
- for i:=1 to n do
- for j:=1 to n do
- readln(a[i,j]);
- writeln;
- writeln('Matrix:');
- for i:=1 to n do
- begin
- for j:=1 to n do
- write(a[i,j],' ');
- writeln;
- end;
- end;
- if (way=2) then
- begin
- writeln('Enter the range of numbers in the matrix:'); //Ввод диапазона значений
- readln(x1);
- writeln(' to ');
- readln(x2);
- writeln;
- while x1>x2 do
- begin
- writeln('Please enter so that the second number is greater than the other: ');
- readln(x1);
- writeln(' to ');
- readln(x2);
- writeln;
- end;
- readln;
- writeln('Matrix:'); //Вывод исходной матрицы
- Randomize;
- for i:=1 to n do
- begin
- for j:=1 to n do
- begin
- a[i,j]:=randomrange(x1,x2);
- write(a[i,j],' ');
- end;
- writeln;
- end;
- end;
- if (way=3) then
- begin
- writeln;
- for i:=1 to m do
- begin
- for j:=1 to m do
- begin
- write(p[i,j],' ');
- a[i,j]:=p[i,j];
- end;
- writeln;
- end;
- n:=m;
- end;
- readln;
- i_max:=1;
- j_max:=1;
- for i:=1 to n do
- begin
- max:=a[i,1];
- for j:=1 to n do
- begin
- if max<=a[i,j] then
- begin
- max:=a[i,j];
- i_max:=i;
- j_max:=j;
- end;
- end;
- a[i_max,j_max]:=a[i,i];
- a[i,i]:=max;
- end;
- writeln('Result:');
- for i:=1 to n do //output array
- begin
- for j:=1 to n do
- write(a[i,j],' ');
- writeln;
- end;
- readln;
- Writeln;
- Writeln('To exit the program, press Enter:');
- readln;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement