// PascalABC.NET 3.1, сборка 1230 от 27.04.2016 begin var n:=ReadInteger('n='); var a:=MatrixRandom(n,n,10,99); var s:=0; var k:=0; for var i:=0 to n-1 do begin for var j:=0 to n-1 do Print(a[i,j]); Writeln; if a[i,i].IsEven then begin s+=a[i,i]; Inc(k) end; end; if k>0 then Writeln('S=',s/k:0:2) else Writeln('На главной диагонали нет четных элементов') end.
#include <bits/stdc++.h>
using namespace std;
int main()
{
char a[8][8];
long long x, y, i, j;
cin >> y >> x;
for(i = 0; i < 8; i++){
for(j = 0; j < 8; j++){
a[i][j] = '.';
}
}
x--;
y--;
if(x - y >= 0){
i = 0;
j = x - y;
}
else{
j = 0;
i = y - x;
}
for(;i < 8 and j < 8;){
a[i][j] = '*';
i++;
j++;
}
if(x + y <= 7){
i = 0;
j = x + y;
}
else{
j = 7;
i = x + y - 7;
}
for(;i < 8 and j >= 0;){
a[i][j] = '*';
i++;
j--;
}
i = 0;
j = x;
for(;i < 8; i++){
a[i][j] = '*';
}
i = y;
j = 0;
for(;j < 8; j++){
a[i][j] = '*';
}
a[y][x] ='Q';
for(i = 0; i < 8; i++){
for(j = 0; j < 8; j++){
cout << a[i][j] << " ";
}
cout << '\n';
}
return 0;
}
Объяснение: