logo

Iterating over main parts of a matrix

#include <stdio.h> #include <stdlib.h> #include <string.h> int main(int argc, char* argv[]) { int matrix[5][5] = { {1, 1, 1, 1, 1}, {2, 2, 2, 2, 2}, {3, 3, 3, 3, 3}, {1, 2, 3, 4, 5}, {1, 2, 3, 4, 5} }; int i, j, n = 5; for (i = 0; i < n / 2; i++) { for (j = 0; j < n; j++) { if (j > i && j < n - i - 1) { printf("%d ", matrix[i][j]); } } printf("\n"); } return 0; }

Courses with this lesson