Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
1.1 kB
3
Indexable
Never
#include <stdio.h>

int main() {
    // multiply the column with the minimum element of the matrix by the row with the maximum element of the matrix and print new matrix
    int n, m, max = 0, min = 0, max_i = 0, min_j = 0;
    printf("Input: ");
    scanf("%d %d", &n, &m);
    int a[n][m];
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            scanf("%d", &a[i][j]);
        }
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            if (a[i][j] > max) {
                max = a[i][j];
                max_i = i;
            }
            if (a[i][j] < min) {
                min = a[i][j];
                min_j = j;
            }
        }
    }
    printf("Output: \n");
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            if (i == max_i) {
                a[i][j] *= min;
            }
            if (j == min_j) {
                a[i][j] *= max;
            }
            printf("%d ", a[i][j]);
        }
        printf("\n");
    }
    return 0;
}

/*
3 3
1 2 3
4 5 6
7 8 9
 */