Question

In: Computer Science

Write a C function that finds and displays the maximum value ina two-dimensional array of...

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

Solutions

Expert Solution

#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


Related Solutions

Write a C++ function that takes a two dimensional dynamic array (matrix) and its sizes and...
Write a C++ function that takes a two dimensional dynamic array (matrix) and its sizes and returns true if the matrix is an upper matrix and returns false otherwise. Remark: A matrix M is an upper matrix if it is a square matrix (row size = column size) and every element M[i][j] = 0 for all i > j. That is all the elements of the matrix below the main diagonal are zero.
C++ ASSIGNMENT: Two-dimensional array Problem Write a program that create a two-dimensional array initialized with test...
C++ ASSIGNMENT: Two-dimensional array Problem Write a program that create a two-dimensional array initialized with test data. The program should have the following functions: getTotal - This function should accept two-dimensional array as its argument and return the total of all the values in the array. getAverage - This function should accept a two-dimensional array as its argument and return the average of values in the array. getRowTotal - This function should accept a two-dimensional array as its first argument...
c++ please 1. Write and test the function maximum that is passed an array of n...
c++ please 1. Write and test the function maximum that is passed an array of n pointers to integers and returns the maximum value among the n integers. The function must use the travellingpointer(1stversion) notation to traverse the array. The function has the following prototype. int maximum ( int *p [ ], int n); 2. Implement the function psum( )that is passed an array of n floats and returns a pointer to the sum of such an array. Print the...
C++ Add a function that finds & displays all the words that begin with the letter...
C++ Add a function that finds & displays all the words that begin with the letter 's'. The text file "dickens.txt" is as follows: It was the best of times, it was the worst of times, it was the age of wisdom, it was the age of foolishness, it was the epoch of belief, it was the epoch of incredulity, it was the season of Light, it was the season of Darkness, it was the spring of hope, it was...
(C++ only please) Write a function called maximum that takes an array of double values as...
(C++ only please) Write a function called maximum that takes an array of double values as a parameter and returns the largest value in the array. The length of the array will also be passed as a parameter. (Note that the contents of the array should NOT be modified.) Write a function called printReverse that takes an array of characters and the length of the array as parameters. It should print the elements of the array in reverse order. The...
Write a code using c# Maximum Sub Array.
Write a code using c# Maximum Sub Array.
Write Matrix Addition 2 D (dimensional) Array program in c++.
Write Matrix Addition 2 D (dimensional) Array program in c++.
Write a c program Write a function to swap two elements of an integer array. Call...
Write a c program Write a function to swap two elements of an integer array. Call the function to swap the first element, i[0] with last element i[n], second element i[1] with the last but one element i[n-1] and so on. Should handle arrays with even and odd number of elements. Call the swap function with the following arrays and print results in each case before and after swapping. i. int arr1[] = {0, 1, 2, 3, 30, 20, 10,...
[C++ Coding question] write a program which inputs data to a two-dimensional array: - Input number...
[C++ Coding question] write a program which inputs data to a two-dimensional array: - Input number of rows r aand number of columns c - Create a two-dimensional array of integers int numbers[r][c] -input data for each element of numbers Your program must compute and display the largest number is each row and column of the number array
C++ please 1. Randomly assign integers in the range of 1-100 to a two-dimensional array. Write...
C++ please 1. Randomly assign integers in the range of 1-100 to a two-dimensional array. Write a program that finds the average value of the rows and the average value of the columns. Display the averages. 2. Create an array of randomly generated numbers in any range. Write a function that takes the array as an argument and returns an array that consists of only the even numbers in the original array. Use the function in a program. 3. Create...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT