Question

In: Computer Science

Minimum value and its position Create a program that: Receive as input in command line the...

Minimum value and its position

Create a program that:

  • Receive as input in command line the sizes m and n of a two dimensional array, and minValue and maxValue between which the random numbers will be generated
  • Generate a array with numbers between minValue and maxValue (inclusive) with the given size (mxn)
  • Compute the minimum value in the array and one of the rows and columns on which it appears.
  • Print the array as a table.
  • Print the minimum value and one of the positions on which it appears.

Run the program 5 times with representative sizes

Solutions

Expert Solution

Since you have not provided the language of your preference, I am providing the code in Java.

CODE

import java.util.Random;

import java.util.Scanner;

public class Main

{

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

int m, n, minValue, maxValue;

System.out.println("Enter the value of m and n: ");

m = sc.nextInt();

n = sc.nextInt();

System.out.println("Enter the value of minValue and maxValue: ");

minValue = sc.nextInt();

maxValue = sc.nextInt();

Random rand = new Random();

int[][] arr = new int[m][n];

for (int i=0; i<m; i++) {

for (int j=0; j<n; j++) {

arr[i][j] = rand.nextInt(maxValue - minValue + 1) + minValue;

}

}

int min = Integer.MAX_VALUE;

int minRow = -1, minColumn = -1;

for (int i=0; i<m; i++) {

for (int j=0; j<n; j++) {

if (arr[i][j] < min) {

min = arr[i][j];

minRow = i;

minColumn = j;

}

}

}

System.out.println("The array is: ");

for (int i=0; i<m; i++) {

for (int j=0; j<n; j++) {

System.out.print(arr[i][j] + " ");

}

System.out.println();

}

System.out.println("The minimum value is: " + min + " which is present at location (" + minRow + ", " + minColumn + ")");

}

}


Related Solutions

Twin elements Create a program that: Input: Receive as input in command line the sizes m...
Twin elements Create a program that: Input: Receive as input in command line the sizes m and n of a two dimensional array Receive as input in command line the minValue and maxValue between which the random numbers will be generated for your two dimensional array Generate: Generate a two-dimensional with numbers between minValue and maxValue (inclusive) with the given size (mxn) Compute: Compute the number of elements that have a neighbour (up, down, left or right) with the same...
Maximum value and its index in an array java program that: Receive as input in command...
Maximum value and its index in an array java program that: Receive as input in command line the size of an array (n) Generate an array with numbers between 1 and 100 (inclusive 1 and 100) with the given size (a) Print the array with the format: {a, b, c, ..., x}, for instance {1, 2} Compute and print in the console the following: maximum value in the array one index on which the maximum value appears (a number from...
IN C LANGUAGE This program takes two command line arguments: an input filename a threshold Your...
IN C LANGUAGE This program takes two command line arguments: an input filename a threshold Your program will create two files: even.txt - contains all integers from the input file that are even and greater than the threshold odd.txt - contains all integers from the input file that are odd and greater than the threshold The input file will exist and only contain a set of integers. It will always be valid data. Output whitespace will be ignored. Name the...
Python programming: Instructions: The python program should respond to user input on a command line Below...
Python programming: Instructions: The python program should respond to user input on a command line Below are the four options - if the user input is A, the program will quit -if the user input is B, the program will display the number of times the prompt has been displayed -if the user input is C, will display whatever is stored. -if the user inputs something else, it will store that user input as a string and append it to...
Modify program so that input comes in as command line arguments. Sample run: ./a.out W8 4...
Modify program so that input comes in as command line arguments. Sample run: ./a.out W8 4 ME 2 finish 2! Output: Consonants: WMfnsh 1) Name your program command_consonants.c. 2) If no command line arguments was provided, your program should print a usage message “Usage: ./a.out input #include<stdio.h> int main() { printf("Input: "); int i = 0; char ch; // array to store consonants char consonant[100]={""}; //do loop to take input do { ch = getchar(); //checks to see if consonants...
Write a program that prints the sum of its command-line arguments (assuming they are numbers). For...
Write a program that prints the sum of its command-line arguments (assuming they are numbers). For example, java Adder 3 2.5 -4.1 should print The sum is 1.4
Using C++ Create a program that asks the user to input a string value and then...
Using C++ Create a program that asks the user to input a string value and then outputs the string in the Pig Latin form. - If the string begins with a vowel, add the string "-way" at the end of the string. For “eye”, it will be “eye-way”. - If the string does not begin with a vowel, first add "-" at the end of the string. Then rotate the string one character at a time; that is, move the...
Create a python program that will: prompt a user for a command Command get_data Level 1:...
Create a python program that will: prompt a user for a command Command get_data Level 1: Take one of the commands my_max my_min my_range my_sum mean median mode fib factorize prime Requirements: Your commands should be case-insensitive You should use python lists to store data You should NOT use built-in python math functions, or math libraries to compute these values Tips: Write one function that will convert a string with comma-separated numbers into a python list with the numbers. You...
java program: Input and output the following details. Your program can only receive the correct input....
java program: Input and output the following details. Your program can only receive the correct input. (For example: a notification will be given if you not enter Char data type for Name) Name: Ali bin Ahmad Occupation: Technician Age: 30 Hometown: Negeri Sembilan Years of Service: 12 Gender: Male
Write a program that takes two command line arguments at the time the program is executed....
Write a program that takes two command line arguments at the time the program is executed. You may assume the user enters only decimal numeric characters. The input must be fully qualified, and the user should be notified of any value out of range for a 23-bit unsigned integer. The first argument is to be considered a data field. This data field is to be is operated upon by a mask defined by the second argument. The program should display...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT