include cstdio define define int main int matrix for int for int matri

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <cstdio>
#define W 4
#define H 4
int main() {
int matrix[W][H];
for (int x = 0; x < W; ++x) {
for (int y = 0; y < H; ++y) {
matrix[x][y] = x | y << 16;
}
}
// Выбираем диагональ
long avg = 0;
int avg_n = 0;
int curr_w = W;
for (int y = 0; y < H; ++y) {
for (int x = 0; x < curr_w; ++x) {
printf("[%d, %d]", matrix[x][y] & 0xFFFF, matrix[x][y] >> 16 & 0xFFFF);
avg += matrix[x][y];
++avg_n;
}
printf("\n");
--curr_w;
}
avg = avg / avg_n;
printf("avg = %ld\n", avg);
return 0;
}