-
Notifications
You must be signed in to change notification settings - Fork 0
/
Matrix
58 lines (47 loc) · 942 Bytes
/
Matrix
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
47
48
49
50
51
52
53
54
55
56
57
58
/ *
void fillMatric(unsigned a[][5], unsigned n);
Write a function to fill the matrix like picture:
0 20 19 17 14
1 0 18 16 13
2 5 0 15 12
3 6 8 0 11
4 7 9 10 0
*/
void fillMatric(unsigned a[][5], unsigned n)
{
int rows = 0;
int col = 0;
int counter = 1;
BYTE diagonal = n;
BYTE top_start_number = (n*n) - diagonal;
BYTE bottom_start_number = 1;
BYTE value;
for(col = 0; col < n; col++)
{
for(rows = col + 1; rows < n; rows++)
{
a[rows][col] = counter;
counter++;
}
}
counter = 20;
for(col = 0; col < n; col++)
{
for(rows = 0; rows <= col; rows++)
{
if(rows == col)
{
a[rows][col] = 0;
}
else
{
a[rows][col] = counter;
counter--;
}
}
}
}
int main()
{
return 0;
}