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.
#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;
}
Comments
Leave a comment