Find Maximum Element in a 3x3 Matrix in C
Problem: Take a 3x3 matrix input from the user and display the maximum number.
đ Explanation:
- Input the matrix values into a 2D array
matrix[3][3]
. - Initialize a variable
max
with the first element. - Compare each element with
max
, update if a larger value is found. - Print the maximum element.
✅ C Program:
#include <stdio.h>
int main() {
int matrix[3][3];
int max;
printf("Enter 9 elements of 3x3 matrix:\n");
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
scanf("%d", &matrix[i][j]);
}
}
max = matrix[0][0];
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
if (matrix[i][j] > max) {
max = matrix[i][j];
}
}
}
printf("Maximum element in the matrix is: %d\n", max);
return 0;
}
đ¤ Sample Output:
Maximum element in the matrix is: 9
āĻোāύ āĻŽāύ্āϤāĻŦ্āϝ āύেāĻ:
āĻāĻāĻি āĻŽāύ্āϤāĻŦ্āϝ āĻĒোāϏ্āĻ āĻāϰুāύ