C Programming code for Max & Min of 2D Array – KLE Tech

Write a Modular C Programming Code for finding the Maximum & Minimum of a 2D Array?

CODE:

#include<stdio.h>
#define ROW 10
#define COL 10

void ReadArray(int [ROW][COL], int, int);
void DisplayArray(int [ROW][COL], int, int);
void SumEachRow(int [ROW][COL], int, int);
void SumEachCol(int [ROW][COL], int, int);
void MinMaxArray(int [ROW][COL], int, int);
main()
{
int r,c,sum;
int a[ROW][COL];
double avg;
printf("Enter the order of 2D matrix: ");
scanf("%d%d",&r,&c);
printf("\nEnter the Elements of Matix:\n");
ReadArray(a,r,c);
printf("\nThe Elements of Matix are\n");
DisplayArray(a,r,c);
MinMaxArray(a,r,c);
}

void ReadArray(int a[ROW][COL], int r, int c)
{
int i,j;
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
scanf("%d",&a[i][j]);
}
}
}

void DisplayArray(int a[ROW][COL], int r, int c)
{
int i,j;
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
printf("%d ",a[i][j]);
}
printf("\n");
}
}

void MinMaxArray(int a[ROW][COL], int r, int c)
{
int i,j,min=a[0][0] ,max=a[0][0];
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
if (a[i][j] > max)
{
max = a[i][j];
}
if (a[i][j] < min)
{
min = a[i][j];
}
}
}
printf("Min is: %d\n",min);
printf("Max is: %d\n",max);
}

OUTPUT

Enter the order of 2D matrix: 3 3

Enter the Elements of Matix:
6
3
2
5
4
9
6
1
5

The Elements of Matix are
6 3 2
5 4 9
6 1 5
Min is: 1
Max is: 9

Process returned 0 (0x0) execution time : 8.667 s
Press any key to continue.

 

Please find some more codes of 1D Arrays, 2D Arrays, Pointers on the below page:

Top 100+ C Programming codes – KLE Technological University

 

Leave a Comment