How to write a C Program to Print Maximum and Minimum Number in Row and Column in C Programming Language ?
This C Program to Print Maximum and Minimum Number in Row and Column.
Solution:
- #include<stdio.h>
- int main()
- {
- int ar[100][100], row, col, i , j, max,min, max2;
- printf("row = ");
- scanf("%d", &row);
- printf("column = ");
- scanf("%d", &col);
- for(i = 0 ; i < row ; i++)
- {
- for(j = 0 ; j < col ; j++)
- {
- printf("ar[%d][%d] = ", i, j);
- scanf("%d", &ar[i][j]);
- }
- }
- max = ar[0][0];
- min = ar[0][0];
- for(i = 0 ; i < row ; i++)
- {
- for(j = 0 ; j < col ; j++)
- {
- if(max < ar[i][j])
- {
- max = ar[i][j];
- }
- if(min > ar[i][j])
- {
- min = ar[i][j];
- }
- }
- }
- max2 = ar[0][0];
- for(i = 0 ; i < row ; i++)
- {
- for(j = 0; j < col ; j++)
- {
- if(max2 < ar[i][j])
- {
- if(ar[i][j] == max)
- {
- continue;
- }
- max2 = ar[i][j];
- }
- }
- }
- printf("maximum number : %d\nminimum number : %d\nsecond maximum number : %d\n",max, min, max2);
- return 0;
- }