//Для проверки результата вывел массив на экран
using System;
namespace App1
{
class Program
{
private static void Main()
{
const int x = -10;
const int y = 20;
int n, k;
Console.Write("Enter n: "); n = int.Parse(Console.ReadLine());
Console.Write("Enter k: "); k = int.Parse(Console.ReadLine());
Console.WriteLine($"{Environment.NewLine}Array:");
int counter = 0;
int[] array = new int[n];
Random rand = new Random();
for (int i = 0; i < array.Length; i++)
{
array[i] = rand.Next(x, y + 1);
if (array[i] > 0 && array[i] % k == 0) { counter++; }
Console.WriteLine($"{i + 1}. {array[i]}");
}
Console.Write(Environment.NewLine);
if (counter > 0) { Console.WriteLine($"В массиве {counter} элементов, соответствующих заданному условию."); }
else { Console.WriteLine("В массиве нет элементов, соответствующих заданному условию."); }
Console.ReadKey();
}
}
}
var a:array[1..10,1..10]of integer;
b:array[1..10,1..10]of integer;
i,j,s1,s2:integer;
begin
for i:=1 to 10 do for j:=1 to 10 do begin a[i,j]:=random(9)+1; b[i,j]:=random(9)+1; end;
for i:=1 to 10 do begin for j:=1 to 10 do write(a[i,j],' '); if j=10 then writeln; end;
writeln;
for i:=1 to 10 do begin for j:=1 to 10 do write(b[i,j],' '); if j=10 then writeln; end;
for i:=1 to 10 do
for j:=1 to 10 do
if i=j then begin
s1:=s1+a[i,j];
s2:=s2+b[i,j];
end;
writeln;
if s1>s2 then for i:=1 to 10 do begin for j:=1 to 10 do write(a[i,j],' '); if j=10 then writeln; end else
for i:=1 to 10 do begin for j:=1 to 10 do write(b[i,j],' '); if j=10 then writeln; end;
end.