1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| #include <iostream> using namespace std; int T; int n; int main() { cin >> T; while (T--) { cin >> n; for (int r = 0; r < n; ++r) { for (int c = 0; c < n; ++c) { cout << (r == c || c == r + 1 || (r == n - 1 && c == 0) ? 1 : 0) << " "; } cout << endl; } cout << endl; } return 0; }
|