WAP that finds the sum of min and max of a mxn matrix

Here is your code :-

#include <stdio.h>

int main() {
    int m, n, matrix[10][10], i, j, max, min;


    printf("Enter the order of the matrix : ");


    scanf("%d%d", &m, &n);


    printf("Enter the Element of Matrix: ");

  // Input of elements of matrix.
    for (i=0; i<m; i++) {
        for (j=0; j<n; j++) {
            scanf("%d", &matrix[i][j]);
        }
    }

// Initialisation of max and min to be
    max = matrix[0][0];
    min = matrix[0][0];


    for (i=0; i<m; i++) {
        for (j=0; j<n; j++) {
            if (max < matrix[i][j]){
            max = matrix[i][j];
            }   
            if (min > matrix[i][j]){
            min = matrix[i][j];
            }   
        }
    }
    printf("The sum of maximum and minimum element of the matrix is %d", max + min);
    
    return 0;
}

 

OUTPUT :-


 

 

Comments

Popular posts from this blog

WAP that inputs two arrays and saves sum of corresponding elements of these arrays in a third array

WAP to add or to multiply two matrices of order nXn.

WAP that swaps values of two variables without third variable.