Answer to Question #160241 in C++ for Rohan

Question #160241

Write a C++ program that inputs a 2D array as arr[5][5] integer values from users then program will accept values from user and showing values index wise. Your program should find the largest element in each row and column.



1
Expert's answer
2021-02-02T10:34:05-0500
#include <iostream>


using namespace std;


int main()
{
	int a[5][5];
	for(int i = 0; i < 5; i++)
	{
		for(int j = 0; j < 5; j++)
		{
			cout << "Enter array's element[" << i << "][" << j << "]: ";
			cin >> a[i][j];
		}
	}
	int max;
	for(int i = 0; i < 5; i++)
	{
		max = a[i][0];
		for(int j = 0; j < 5; j++)
		{
			if(max < a[i][j]) max = a[i][j];
		}
		cout << "In " << i+1 << " row max element is: " << max << endl;
	}
	cout << endl;
	for(int i = 0; i < 5; i++)
	{
		max = a[0][i];
		for(int j = 0; j < 5; j++)
		{
			if(max < a[j][i]) max = a[j][i];
		}
		cout << "In " << i+1 << " column max element is: " << max << endl;
	}
	return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog