We all know how to find the elements above the main diagonal in a square matrix. And what if the matrix is not square, but simply rectangular, and how to find in it all the elements above the main diagonal? The usual if (i <= j) not enough.
Suppose there is such a code that makes all the elements above the diagonal 0, the rest are random:
int n = 10; int m = 16; int** arr = (int**)malloc(sizeof(int*)*m); for (int i = 0; i < m; i++) { arr[i] = (int*)malloc(sizeof(int)*n); } for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { arr[i][j] = rand() % 9 + 1; if (i <= j) //Какое-то корректное условие вместо данного { arr[i][j] = 0; } printf("%d ", arr[i][j]); } printf("\n"); } How to solve this problem?