forked from kothariji/competitive-programming
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEVENM(1).cpp
38 lines (38 loc) · 827 Bytes
/
EVENM(1).cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <bits/stdc++.h>
using namespace std;
main()
{
int t;
cin >> t;
while (t--)
{
int n, i, j;
cin >> n;
int a[n][n], b[n][n], x = 2, y = 1;
for (i = 0; i < n; i++)
for (j = 0; j < n; j++)
a[i][j] = 0;
for (i = 0; i < n; i++)
for (j = 0; j < n; j++)
{
if ((i + j) % 2 == 0)
{
a[i][j] = y;
y = y + 2;
}
else
{
a[i][j] = x;
x = x + 2;
}
}
for (i = 0; i < n; i++)
{
for (j = 0; j < n; j++)
{
cout << a[i][j] << " ";
}
cout << endl;
}
}
}