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
Post a Comment