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(...
Question 2. Write a complete C++ program that uses a 2-dimensional array with 4 rows and...
Question 2. Write a complete C++ program that uses a 2-dimensional array with 4 rows and 30 columns. Row represents sections of a course and column represents the students, value inside each position of the array is the final exam grade for each students. Fill the array with random numbers between 40 and 100. Calculate the total, average, maximum, minimum for each section. Please do it simple. code
Write Matrix Addition 2 D (dimensional) Array program in c++.
Write Matrix Addition 2 D (dimensional) Array program in c++.
Write a program that creates a two-dimensional array initialized with test data. Use any primitive data...
Write a program that creates a two-dimensional array initialized with test data. Use any primitive data type that you wish. The program should have the following methods: -getTotal. This method should accept a two-dimensional array as its argument and return the total of all the values in the array. -getAverage. This method should accept a two-dimensional array as its argument and return the average of all the values in the array. -getRowTotal. This method should accept a two-dimensional array as...
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 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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT