var a: array[1..n, 1..n] of integer; i, j, aii: integer;
begin Randomize; Writeln('Исходный массив'); for i := 1 to n do begin for j := 1 to n do begin a[i, j] := Random(101) - 50; Write(a[i, j]:4) end; Writeln end; Writeln('Результирующий массив'); for i := 1 to n do begin aii:=a[i,i]; for j:=1 to n do begin if a[i,j]<aii then a[i,j]:=1 else a[i,j]:=0; Write(a[i,j]:4) end; Writeln end end.
#include <iostream>
#include <stdlib.h>
#include <time.h>
void Swap(int & a, int & b) {int t = a; a = b; b = t;}
int main(){
srand(time(NULL));
const int n = 6;
int f[n], s[n];
for (unsigned int i = 0; i < n; ++i) {
f[i] = rand() % 12 + 5;
s[i] = f[i];
}
// Меняем 5 и 6 элементы местами
Swap(s[4], s[5]);
s[3] *= 3;
std::cout << "First: ";
for (unsigned int i = 0; i < n; ++i) {
std::cout << f[i] << ", ";
}
std::cout << std::endl;
std::cout << "Second: ";
for (unsigned int i = 0; i < n; ++i) {
std::cout << s[i] << ", ";
}
std::cout << std::endl;
return 0;
}
n = 9;
var
a: array[1..n, 1..n] of integer;
i, j, aii: integer;
begin
Randomize;
Writeln('Исходный массив');
for i := 1 to n do
begin
for j := 1 to n do
begin
a[i, j] := Random(101) - 50;
Write(a[i, j]:4)
end;
Writeln
end;
Writeln('Результирующий массив');
for i := 1 to n do
begin
aii:=a[i,i];
for j:=1 to n do
begin
if a[i,j]<aii then a[i,j]:=1 else a[i,j]:=0;
Write(a[i,j]:4)
end;
Writeln
end
end.
Тестовое решение:
Исходный массив
-11 19 48 32 -6 -39 -45 -13 -27
44 20 -44 27 -50 14 -19 -12 32
2 48 -16 40 -8 -38 35 -15 41
-1 -24 -18 35 -49 -11 22 -4 -1
36 -26 -8 -2 -9 -17 41 44 -13
0 -25 -6 -35 -18 -6 -28 46 44
5 -1 -23 36 47 -41 -30 7 -39
41 -41 19 17 -45 5 -35 -4 -36
-11 -46 6 -50 49 -2 26 -15 -40
Результирующий массив
0 0 0 0 0 1 1 1 1
0 0 1 0 1 1 1 1 0
0 0 0 0 0 1 0 0 0
1 1 1 0 1 1 1 1 1
0 1 0 0 0 1 0 0 1
0 1 0 1 1 0 1 0 0
0 0 0 0 0 1 0 0 1
0 1 0 0 1 0 1 0 1
0 1 0 1 0 0 0 0 0