int n,m;
cin >> n >> m;
int a[n][m];
int val = 0;
for(int j = 0; j < m; j++){
for(int i = 0; j - i >= 0 && i < n; i++){
a[i][j-i] = val;
val++;
}
for(int i = 1; i < n; i++){
for(int j = 0; i+j < n && m - 1 - j >= 0; j++){
a[i+j][m-1-j] = val;
Copyright © 2025 SCHOLAR.TIPS - All rights reserved.
Answers & Comments
int n,m;
cin >> n >> m;
int a[n][m];
int val = 0;
for(int j = 0; j < m; j++){
for(int i = 0; j - i >= 0 && i < n; i++){
a[i][j-i] = val;
val++;
}
}
for(int i = 1; i < n; i++){
for(int j = 0; i+j < n && m - 1 - j >= 0; j++){
a[i+j][m-1-j] = val;
val++;
}
}