#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 char row_diff_matrix[ROWS][COLS] = {' '}; // Row-wise differences char col_diff_matrix[ROWS][COLS] = {' '}; // Column-wise differences char combined_matrix[ROWS][COLS] = {' '}; // 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]); if (diff > 100) { row_diff_matrix[i][j] = '*'; } else { row_diff_matrix[i][j] = ' '; } } row_diff_matrix[i][COLS - 1] = ' '; // 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]); if (diff > 100) { col_diff_matrix[i][j] = '*'; } else { col_diff_matrix[i][j] = ' '; } } col_diff_matrix[ROWS - 1][j] = ' '; // 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] == '*') || (col_diff_matrix[i][j] == '*')) { combined_matrix[i][j] = '*'; } else { combined_matrix[i][j] = ' ';} } } } void print_matrix(char 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("%c", 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; }