How can I decrease code length?
You could split your big for loop into 2 smaller ones. The first one would print all diagonals up to the main one, and the other one the remaining ones.
For instance, let's say there's a matrix like:
1 2 3
4 5 6
7 8 9
Then, your first loop would print 1 4 2 7 5 3 and the second one 8 6 9. The code would look conciser and more readable too:
for (int i = 0; i < N; i++) {
for (int j = 0; j <= i; j++) {
printf("%d ", pixel_array[i - j][j]);
}
}
for (int j = 0; j < N - 1; j++) {
for (int i = N - 1; i > j; i--) {
printf("%d ", pixel_array[i][N - i + j]);
}
}
How can I improve the efficiency of this program?
I don't think it's possible to make it more efficient than O(n2) as you have to go through all matrix elements to print them diagonally.
Any other programming practices to be implemented
Rather than using an int type for defining a size of your array, you could use uint32_t (or uint16_t or uint64_t - it depends on your requirements). You size cannot be negative, anyways.
As you currently define your logic in main() you could create a separate method instead like printDiagonally(int32_t** array, const uint32_t rows, const uint32_t columns). Then, you could use this method anywhere in your app.