Good.
However, you had the lines 12-16 nested loop uncommented, because I see the values 1-10 in the lower triangle. That loop works as expected, but it now distracts from the doings of the 17-22 loop.
Furthermore, these loops might overwrite, what the loop on lines 9-10 does. That loop (setting some elements to 0) is now unnecessary, because the entire array is initialized to 0. However, it was the source of a compiler warning:
10:14: warning: 'j' is used uninitialized in this function [-Wuninitialized] |
Why? Look closely:
1 2
|
for (i = 0; i < N; i++)
a[ i ][ j ] = 0;
|
What is the value of j? If your code now initializes j to 0, then the loop sets the first column of the array to 0.
I bet that is not the intention. Perhaps the loop should set the diagonal to 0?
If so, different indices have to be used.
The elements of the diagonal are:
a[0][0] a[1][1] a[2][2] a[3][3] a[4][4]
Coincidentally, those seem to be the elements that the lines 17-22 loop is writing to (but should not). Perhaps an another indexing error? (The answer is yes.)
What is the k used for? It is written into elements of the array. Each iteration increments the k by one, so we get numbers 1 2 3 4 5 ..
The loop counters decide where to write and the k says what to write.