Advertisement
Guest User

Untitled

a guest
Dec 11th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 2.34 KB | None | 0 0
  1. program lab5;
  2.  
  3. {$APPTYPE CONSOLE}
  4.  
  5. uses
  6.   SysUtils, Math;
  7.  
  8. const m=4;
  9. type TM=array [1..m,1..m] of Integer;
  10. const p: TM=((6, -17, 92, 60),
  11.              (30, 23, 0, -1),
  12.              (-24, 75, 12, 12),
  13.              (44, 3, 47, -19));
  14.  
  15. Var A:array[1..1000] of array[1..1000] of Integer;
  16.     i, j, max, i_max, j_max, n, way, x1, x2: Integer;
  17.  
  18. begin
  19. n:=0;
  20. writeln('Enter the way to set the array: 1 - keyboard input, 2 - randomly, 3 - typed constant ');
  21. readln(way);
  22. while (way<>1) and (way<>2) and (way<>3) do
  23.   begin
  24.   write('Please enter only 1, 2 or 3: ');
  25.   readln(way);
  26.   end;
  27.  
  28. if (way=1) or (way=2) then
  29.   begin write('Enter the order of the matrix: ');
  30.   readln(n);
  31.   end;
  32.  
  33. if (way=1) then      //keyboard input
  34.   begin
  35.   writeln('Enter the elements of the array:');
  36.   for i:=1 to n do
  37.     for j:=1 to n do
  38.       readln(a[i,j]);
  39.   writeln;
  40.   writeln('Matrix:');
  41.   for i:=1 to n do
  42.     begin
  43.     for j:=1 to n do
  44.       write(a[i,j],' ');
  45.     writeln;
  46.     end;
  47.   end;
  48.  
  49. if (way=2) then
  50.   begin
  51.   writeln('Enter the range of numbers in the matrix:');      //Ввод диапазона значений
  52.   readln(x1);
  53.   writeln(' to ');
  54.   readln(x2);
  55.   writeln;
  56.   while x1>x2 do
  57.     begin
  58.     writeln('Please enter so that the second number is greater than the other: ');
  59.     readln(x1);
  60.     writeln(' to ');
  61.     readln(x2);
  62.     writeln;
  63.     end;
  64.   readln;
  65.   writeln('Matrix:');                    //Вывод исходной матрицы
  66.   Randomize;
  67.   for i:=1 to n do
  68.     begin
  69.     for j:=1 to n do
  70.       begin
  71.       a[i,j]:=randomrange(x1,x2);
  72.       write(a[i,j],' ');
  73.       end;
  74.     writeln;
  75.     end;
  76.   end;
  77.  
  78. if (way=3) then
  79.   begin
  80.   writeln;
  81.   for i:=1 to m do
  82.     begin
  83.     for j:=1 to m do
  84.       begin
  85.       write(p[i,j],' ');
  86.       a[i,j]:=p[i,j];
  87.       end;
  88.     writeln;
  89.     end;
  90.   n:=m;
  91.   end;
  92. readln;
  93.  
  94. i_max:=1;
  95. j_max:=1;
  96. for i:=1 to n do
  97.   begin
  98.   max:=a[i,1];
  99.   for j:=1 to n do
  100.     begin
  101.     if max<=a[i,j] then
  102.       begin
  103.       max:=a[i,j];
  104.       i_max:=i;
  105.       j_max:=j;
  106.       end;
  107.     end;
  108.   a[i_max,j_max]:=a[i,i];
  109.   a[i,i]:=max;
  110.   end;
  111.  
  112. writeln('Result:');
  113. for i:=1 to n do             //output array
  114.   begin
  115.   for j:=1 to n do
  116.     write(a[i,j],' ');
  117.   writeln;
  118.   end;
  119. readln;
  120. Writeln;
  121. Writeln('To exit the program, press Enter:');
  122. readln;
  123. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement