Untitled
unknown
plain_text
2 years ago
473 B
6
Indexable
#include <iostream>
using namespace std;
int main() {
int count = 1;
int n = 5;
int arr[5][5];
for (int i = 0; i < n; i++) {
for (int j = n-1, k = i; k >= 0; j--,k--) {
arr[j][k] = count++;
}
}
for (int i = 1; i < n; i++) {
for (int j = n-i-1,k =n-1; j >= 0; j--,k--) {
arr[j][k] = count++;
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
cout << arr[i][j] << " ";
}
cout << endl;
}
return 0;
}
Editor is loading...
Leave a Comment