Program to pick & display the largest element of an input matrix

#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 {
printf("Enter data for row no. %2d",row+1);
for (col=0;col scanf("%d",&a[row][col]);
}
printf(" TABLE 1");
for (row=0;row {
printf(" ");
for (col=0;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 {
for (j=0;j {
if (a[i][j]>largest)
largest=a[i][j];
}
}
printf("The largest element of the matrix is %d",largest);
return;
}

No comments:

Post a Comment