In: Computer Science
Write a C function that finds and displays the maximum value in a two-dimensional array of integers. The array should be declared as a 10-row-by-20-column array of integers in main (), and the starting the address of the array should be passed to the function. Modify the function so that it also displays the rows and columns number of the element with the maximum value
#include
void printMax(int arr[10][20]){
int i,j,maxIndexI = 0,maxIndexJ = 0,maxVal =
arr[0][0];
for(i = 0;i<10;i++){
for(j = 0;j<20;j++){
if(maxVal<=arr[i][j]){
maxIndexI = i;
maxIndexJ = j;
maxVal = arr[i][j];
}
}
}
printf("Max value is %d at position
(%d,%d)\n",maxVal,maxIndexI,maxIndexJ);
}
int main() {
int a[10][20];
int i,j;
printf("Enter array a:\n");
for(i = 0;i<10;i++){
for(j =0;j<20;j++){
scanf("%d",&a[i][j]);
}
}
printf("\n");
printMax(a);
return 0;
}
21 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0
1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0
1 2 13 4 5 6 7 8 49 0 1 2 3 54 5 6 7 8 9 0
1 2 3 14 5 6 7 8 9 06 1 2 3 4 5 6 7 8 9 0
1 2 3 4 5 6 7 38 9 0 1 2 3 4 5 56 7 8 9 0
1 2 23 4 15 6 7 8 9 0 1 2 3 4 5 6 7 85 9 0
1 2 3 4 5 6 7 8 9 0 11 2 3 4 5 6 7 8 9 0
1 2 3 4 5 6 7 8 9 0 1 2 3 4 55 6 7 8 9 0
1 2 33 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0
1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0