Question

In: Computer Science

[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

Solutions

Expert Solution

ANSWER: Here I am giving you the code and output if you have any problem then you can comment or like my solution.

CODE:

#include <iostream>
using namespace std;

int main()
{

int r,c;
cout<<"Input row and column for the matrix :";
cin>>r>>c;
int A[r+1][c+1] ;
A[r+1][c+1] = {0};
for(int i=0;i<r+1;i++)
for(int j=0;j<c+1;j++)
A[i][j]=0;


for (int x = 0; x < r; ++x)// Entering the values in the array
{
for (int y = 0; y < c; ++y)
{
cout << "Enter in value for row " << x << ", column " << y << ".\n";
cin >> A[x][y];
}
}

cout << "Input:" << endl;// Printing the you array
for (int x = 0; x < r; ++x)
{
for (int y = 0; y < c; ++y)
{
cout << A[x][y] << "\t";
}
cout << "\n";
}

// Finds the max down each column in the array
for (int x = 0; x < r; ++x)
{
for (int y = 0; y < c; ++y)
{
if (A[x][c] < A[x][y])
A[x][c] = A[x][y];
}
}

// Finds the min across the array (along row)
for (int y = 0; y < r; ++y)
{
for (int x = 0; x < c; ++x)
{
// Assign the min to a value in that row.
A[r][y] = A[1][y];
if (A[r][y] > A[x][y])
A[r][y] = A[x][y];
}
}

for(int i=0;i<c;i++)
{
cout<<"\nMaximum in row "<< i+1<<": "<<A[i][c];

}

for(int i=0;i<r;i++)
cout<<"\nMaximum in column "<<i+1<<": "<<A[r][i];


return 0;
}

OUTPUT:


Related Solutions

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...
Write a program that creates a two-dimensional array initialized with test data. The program should have...
Write a program that creates a two-dimensional array initialized with test data. The program should have the following functions: Hi There I really appreciate your help with this project. ▪ getTotal . This function should accept a 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 all the values in the array. ▪ getRowTotal ....
One dimensional dynamic array Write a function that returns the number of integers in an input...
One dimensional dynamic array Write a function that returns the number of integers in an input file stream with the following interface: int findNumber(ifstream &x); Then, use this number to dynamically allocate an integer array. Write another function that reads each number in an input file stream and assign the value to the corresponding array element with the following interface: void assignNumber(ifstream &x, int y[ ]); In your main( ), first open “in.dat” as an input file. Next, apply findNumber(...
Write Matrix Addition 2 D (dimensional) Array program in c++.
Write Matrix Addition 2 D (dimensional) Array program in c++.
Write a Java program that will use a two-dimensional array and modularity to solve the following...
Write a Java program that will use a two-dimensional array and modularity to solve the following tasks: Create a method to fill the 2-dimensional array with (random numbers, range 0 - 30). The array has rows (ROW) and columns (COL), where ROW and COL are class constants. Create a method to print the array. Create a method to find the largest element in the array Create a method to find the smallest element in the array Create a method to...
Write a Java program that will use a two-dimensional array and modularity to solve the following...
Write a Java program that will use a two-dimensional array and modularity to solve the following tasks: 1. Create a method to generate a 2-dimensional array (random numbers, range 0 - 500). The array has ROW rows and COL columns, where ROW and COL are class constants. 2. Create a method to print the array. 3. Create a method to find the largest element in the array 4. Create a method to find the smallest element in the array 5....
Write a Java program that will use a two-dimensional array and modularity to solve the following...
Write a Java program that will use a two-dimensional array and modularity to solve the following tasks: Create a method to generate a 2-dimensional array (random numbers, range 0 - 500). The array has ROW rows and COL columns, where ROW and COL are class constants. Create a method to print the array. Create a method to find the largest element in the array Create a method to find the smallest element in the array Create a method to find...
Write C program Multidimensional Arrays Design a program which uses two two-dimensional arrays as follows: an...
Write C program Multidimensional Arrays Design a program which uses two two-dimensional arrays as follows: an array which can store up to 50 student names where a name is up to 25 characters long an array which can store marks for 5 courses for up to 50 students The program should first obtain student names and their corresponding marks for a requested number of students from the user. Please note that the program should reject any number of students that...
Write a Java program to create an array of a specific size (which is an input...
Write a Java program to create an array of a specific size (which is an input from the user) and fill it with random numbers between 1 and 100. Then sort the array and count how many of these numbers are originally at sorted position. Display that original array, the sorted array, and the count (number of elements originally at sorted position).
C Programming Only Write a program that declares a one-dimensional array of integers with 24 elements....
C Programming Only Write a program that declares a one-dimensional array of integers with 24 elements. Fill the array with random integers (use a loop). Neatly output each element in the one-dimensional array. Next convert your one-dimensional array of 24 elements into a two-dimensional array of 6 x 4 elements. Neatly output each element of the two-dimensional array. The values will be identical to the one-dimensional array – you’re just converting from one dimension to two.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT