Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
int fields[50][50] = {}; // set to zero
for (int i = 0; i < n; i++) {
int v = i+1;
fields[0][i] = v;
fields[n-1][i] = v;
fields[i][0] = 1;
fields[i][n-1] = n;
fields[i][i] = v;
fields[n-1-i][i] = v;
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (fields[i][j]) cout << fields[i][j] << ' ';
else cout << " ";
}
cout << endl;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment