Question

IN C#.Develop a program that prints out the location of the largest value in a two-dimensional...

IN C#.Develop a program that prints out the location of the largest value in a two-dimensional array. The largest values may appear more than once in the array, so you must only print out the first instance. The program defines method locateLargest() that takes a two-dimensional array of integers and returns the location (row index and column index) of the first largest value as a single-dimensional array. The program main method prompts the user to enter a 3-by-4 matrix, prints out the matrix, and then calls method locateLargest(). Finally, it prints out the array returned by method locateLargest(). Document your code, and organize and space the outputs properly as shown below. Sample run 1: [SIMILAR FORMAT OF INPUT ABOVE, BUT DIFFERENT NUMBERS] The entered matrix: 9 1 2 4 2 11 18 20 3 20 3 12 First largest value is located at row 1 and column 3 Sample run 2: [SIMILAR FORMAT OF INPUT ABOVE, BUT DIFFERENT NUMBERS] The entered matrix: 19 11 22 44 29 51 81 20 23 90 45 90 First largest value is located at row 2 and column 1 Sample run 3: [SIMILAR FORMAT OF INPUT ABOVE, BUT DIFFERENT NUMBERS] The entered matrix: 89 11 22 44 29 51 80 20 33 10 45 10 First largest value is located at row 0 and column 0

0 0
Add a comment Improve this question Transcribed image text
Answer #1

using System;
class GFG {
  
static int N = 4;
static int M = 4 ;
  
// Function to find max element
// mat[,] : 2D array to find max element
static int findMax(int[,] mat)
{
  
// Initializing max element as INT_MIN
int maxElement = int.MinValue;
  
// checking each element of matrix
// if it is greater than maxElement,
// update maxElement
for (int i = 0; i < N; i++) {
  
for (int j = 0; j < M; j++) {
  
if (mat[i,j] > maxElement) {
  
maxElement = mat[i,j];
}
  
}
  
}

  
// finally return maxElement
return maxElement;
}
  
  
// Driver code
public static void Main()
{
  
// matrix
int[,]mat = {{ 1, 2, 3, 4},
{25, 6, 7, 8},
{9, 10, 11, 12},
{13, 14, 15, 16}};
  
Console.Write(findMax(mat)) ;

}
  
}

Add a comment
Know the answer?
Add Answer to:
IN C#.Develop a program that prints out the location of the largest value in a two-dimensional...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • SOLVE IN PYTHON: Exercise #2: Develop a program (name it LocateLargestElement) that prints out the location...

    SOLVE IN PYTHON: Exercise #2: Develop a program (name it LocateLargestElement) that prints out the location of the first largest value in a two-dimensional array. The largest values may appear more than once in the array. The program defines method locateLargest() that takes a two-dimensional array of integers and returns the location (row index and column index) of the first largest value as a single-dimensional array. The program main method prompts the user to enter a 3-by-4 matrix, prints out...

  • This needs to be in python, however, I am having trouble with the code. Is there...

    This needs to be in python, however, I am having trouble with the code. Is there any way to use the code that I already have under the main method? If so, what would be the rest of the code to finish it? #Create main method def main(): #Create empty list list=[] #Display to screen print("Please enter a 3 x 4 array:") #Create loop for rows and have each entered number added to list for i in range(3): list.append([int(x) for...

  • I need this code in C++. Should be able to read from a file as stated...

    I need this code in C++. Should be able to read from a file as stated in the directions Exercise #1: Develop a program that prints out the sum of each column of a two-dimensional array The program defines method sumColumn takes a two-dimensional array of integers and returns a single dimensional array that stores the sum of columns of the passed array. The program main method prompts the user to enter a 3-by-4 array, prints out the array, and...

  • this language is JAVA 2. Design a class named Location for locating a maximum value and...

    this language is JAVA 2. Design a class named Location for locating a maximum value and its location in a two-dimensional array. The class contains public data fields row, column, and maxValue that store the maximal value and its indices in a two-dimensional array with row and column as int types and maxValue as a double type. Write the following method that returns the location of the largest element in a two-dimensional array: Public static Location locateLargest(double [][] a) Create...

  • I need assistance writing the following Java class. Design a class named Location for locating a...

    I need assistance writing the following Java class. Design a class named Location for locating a maximal value and its location in a two-dimensional array. The class contains public data fields row, column, and maxValue that store the maximal value and its indices in a two-dimensional array with row and column as int types and maxValue as a double type. Write the following method that returns the location of the largest element in a two-dimensional array: public static Location locateLargest(double[][]...

  • in c++ Develop a program (name it AddMatrices) that adds two user provided matrices. The matrices...

    in c++ Develop a program (name it AddMatrices) that adds two user provided matrices. The matrices must of the same size. The program defines method Addition() that takes two two-dimensional arrays of integers and returns their addition as a two-dimensional array. The program main method defines two 3-by-3 arrays of type integer. The method prompts the user to initialize the arrays. Then it calls method Addition(). Finally, it prints out the array retuned by method Addition(). Document your code, and...

  • C++ Lab 11 – Is This Box a Magic Box? Objectives: Define a two dimensional array Understand h...

    C++ Lab 11 – Is This Box a Magic Box? Objectives: Define a two dimensional array Understand how to traverse a two dimensional array Code and run a program that processes a two dimensional array Instructions: A magic square is a matrix (two dimensional arrays) in which the sum of each row, sum of each column, sum of the main diagonal, and sum of the reverse diagonal are all the same value. You are to code a program to determine...

  • Write a C PROGRAM that will read in 10 floating-point numbers from the keyboard and load...

    Write a C PROGRAM that will read in 10 floating-point numbers from the keyboard and load them into an array. Add up all the values and store the answer in a variable. Find the largest and smallest number in the array. Put each into its own variable. Print to the screen the sum, largest value, and smallest value. Copy the array to a second array in reverse order. Print out the second array. Read in 20 integer numbers, all in...

  • This is for Java. Create ONE method/function that will return an array containing the row and...

    This is for Java. Create ONE method/function that will return an array containing the row and column of the largest integer i the 2D array. If the largest number is located on row 2, column 1, the method needs to return row 2 and column one. Do not use more than one method. Use the code below as the main. Please comment any changes. in java Given the main, create a method that RETURNS the largest number found in the...

  • Program in C++! Thank you in advance! Write a menu based program implementing the following functions: (1) Write a funct...

    Program in C++! Thank you in advance! Write a menu based program implementing the following functions: (1) Write a function that prompts the user for the name of a file to output as a text file that will hold a two dimensional array of the long double data type. Have the user specify the number of rows and the number of columns for the two dimensional array. Have the user enter the values for each row and column element in...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT