-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2.cpp
More file actions
49 lines (45 loc) · 662 Bytes
/
2.cpp
File metadata and controls
49 lines (45 loc) · 662 Bytes
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
39
40
41
42
43
44
45
46
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int arr[1000][1000];
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n,i,j;
scanf("%d",&n);
int l,cnt, k=1;
for(i=(n+1)/2;i>=1;i--)
{
cnt=1;
int u = 1;
for(j=k;j<=n;j++)
arr[i][j] = cnt++;
for(l=cnt; l<=n; l++)
arr[i][u++] = l;
k++;
}
k = (n+1)/2+1;
int s = 0;
for(i=(n+1)/2+1;i<=n;i++)
{
cnt=1;
int u = 1;
for(j=n-s;j<=n;j++)
arr[i][j] = cnt++;
for(l=cnt; l<=n; l++)
arr[i][u++] = l;
k++;
s++;
}
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
printf("%d ",arr[i][j]);
printf("\n");
}
}
return 0;
}