const n=5;
var
a:array [1..n,1..n] of integer;
i,j,k:integer;
begin
k:=0;
for i:=1 to n do
for j:=1 to n do
a[i,j]:=random(151)-50;
write(a[i,j]:4);
if (a[i,j] mod 5 =0) then
inc(k);
end;
writeln;
if k<>0 then
if a[i,j]=k then a[i,j]:=0;
writeln('K= ',k);
end
else
a[i,j]:=0;
writeln('K= 0');
end.
#include <iostream>
using namespace std;
int main()
{
int n,kl=0;double sum = 0;
cin >> n;
int** a;
a= new int* [n];
for (int i = 0; i < n; i++)
a[i] = new int[n];
for (int j = 0; j < n; j++)
a[i][j] = rand() % 10;
}
cout << endl;
cout<<a[i][j]<<" ";
for (int j = 0; j < n - i; j++)
if (a[i][j] != 0)
sum += a[i][j]; kl++;
cout << endl << sum/kl;
Объяснение:
const n=5;
var
a:array [1..n,1..n] of integer;
i,j,k:integer;
begin
k:=0;
for i:=1 to n do
begin
for j:=1 to n do
begin
a[i,j]:=random(151)-50;
write(a[i,j]:4);
if (a[i,j] mod 5 =0) then
inc(k);
end;
writeln;
end;
writeln;
if k<>0 then
begin
for i:=1 to n do
begin
for j:=1 to n do
begin
if a[i,j]=k then a[i,j]:=0;
write(a[i,j]:4);
end;
writeln;
end;
writeln('K= ',k);
end
else
begin
for i:=1 to n do
begin
for j:=1 to n do
begin
a[i,j]:=0;
write(a[i,j]:4);
end;
writeln;
end;
writeln('K= 0');
end;
end.
#include <iostream>
using namespace std;
int main()
{
int n,kl=0;double sum = 0;
cin >> n;
int** a;
a= new int* [n];
for (int i = 0; i < n; i++)
a[i] = new int[n];
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
a[i][j] = rand() % 10;
}
for (int i = 0; i < n; i++)
{
cout << endl;
for (int j = 0; j < n; j++)
cout<<a[i][j]<<" ";
}
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n - i; j++)
if (a[i][j] != 0)
{
sum += a[i][j]; kl++;
}
}
cout << endl << sum/kl;
}
Объяснение: