C Programming Code Examples C > Beginners Lab Assignments Code Examples Program to pick & display the largest element of an input matrix Program to pick & display the largest element of an input matrix #include <stdio.h> #include <conio.h> #include <math.h> #define maxrows 30 #define maxcols 30 void largest(int a[][maxcols],int nrows,int ncols); void readinput(int a[][maxcols],int m,int n); void main() { int nrows,ncols; int a[maxrows][maxcols]; clrscr(); printf("How many rows in the matrix? "); scanf("%d",&nrows); printf("How many columns in the matrix? "); scanf("%d",&ncols); printf(" Table "); readinput(a,nrows,ncols); largest(a,nrows,ncols); getch(); } void readinput(int a[][maxcols],int m,int n) { int row,col; for (row=0;row<m;++row) { printf(" Enter data for row no. %2d ",row+1); for (col=0;col<n;++col) scanf("%d",&a[row][col]); } printf(" TABLE 1"); for (row=0;row<m;++row) { printf(" "); for (col=0;col<n;++col) printf("%d%c",a[row][col],' '); } return; } void largest(int a[][maxcols],int m,int n) { int i,j,largest; largest = a[0][0]; for (i=0;i<m;++i) { for (j=0;j<n;++j) { if (a[i][j]>largest) largest=a[i][j]; } } printf(" The largest element of the matrix is %d",largest); return; }