Untitled

mail@pastecode.io avatar
unknown
plain_text
23 days ago
473 B
3
Indexable
Never
#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;
}

Leave a Comment