#include #include #define ROWS 10 #define COLS 10 // Given 10x10 matrix int array[ROWS][COLS] = { {128, 128, 128, 128, 128, 128, 128, 128, 128, 128}, {128, 128, 128, 128, 0, 0, 128, 128, 128, 128}, {128, 128, 128, 128, 0, 0, 128, 128, 128, 128}, {128, 128, 128, 0, 0, 0, 0, 128, 128, 128}, {128, 0, 0, 0, 0, 0, 0, 0, 0, 128}, {128, 0, 0, 0, 0, 0, 0, 0, 0, 128}, {128, 128, 128, 0, 0, 0, 0, 128, 128, 128}, {128, 128, 128, 128, 0, 0, 128, 128, 128, 128}, {128, 128, 128, 128, 0, 0, 128, 128, 128, 128}, {128, 128, 128, 128, 128, 128, 128, 128, 128, 128} }; // Output matrices int row_diff_matrix[ROWS][COLS] = {0}; // Row-wise differences int col_diff_matrix[ROWS][COLS] = {0}; // Column-wise differences int combined_matrix[ROWS][COLS] = {0}; // Final combined matrix void compute_row_diff() { for (int i = 0; i < ROWS; i++) { for (int j = 0; j < COLS - 1; j++) { int diff = abs(array[i][j] - array[i][j + 1]); row_diff_matrix[i][j] = (diff > 100) ? 1 : 0; } row_diff_matrix[i][COLS - 1] = 0; // Ensure last column remains 0 } } void compute_col_diff() { for (int j = 0; j < COLS; j++) { for (int i = 0; i < ROWS - 1; i++) { int diff = abs(array[i][j] - array[i + 1][j]); col_diff_matrix[i][j] = (diff > 100) ? 1 : 0; } col_diff_matrix[ROWS - 1][j] = 0; // Ensure last row remains 0 } } void combine_matrices() { for (int i = 0; i < ROWS; i++) { for (int j = 0; j < COLS; j++) { // Ensure row 3, column 3 gets correctly set if ((row_diff_matrix[i][j] == 1) || (col_diff_matrix[i][j] == 1)) { combined_matrix[i][j] = 1;} else { combined_matrix[i][j] = 0;} } } } void print_matrix(int matrix[ROWS][COLS], const char* title) { printf("\n%s:\n", title); for (int i = 0; i < ROWS; i++) { for (int j = 0; j < COLS; j++) { printf("%d ", matrix[i][j]); } printf("\n"); } } int main() { compute_row_diff(); print_matrix(row_diff_matrix, "Row-wise Difference Matrix"); compute_col_diff(); print_matrix(col_diff_matrix, "Column-wise Difference Matrix"); combine_matrices(); print_matrix(combined_matrix, "Final Combined Matrix"); return 0; }