Hi there! I need to find the mimimum element in two-dimensional(4,4) array by row and maximum element by column and store them in another array (5,5).Maybe I did not explain properly.

That's how it should look new array (5,5):

``````1 2 3 4 min
1 2 3 4 min
1 2 3 4 min
m m m m 0
``````

*m - max

So this is the first array:

``````int array[4][4];
int i, j;

for(i = 0; i < 4; i++) {
for(j = 0; j < 4; j++) {
cout << "\n array[" << i + 1 << "][" << j + 1 <<"]=";
cin >> array[i][j];
}
}
``````

With this I try to find the min of each row:

``````int min[4];
for (i = 0; i<4; i++) {
min[i] = array[0][i];
for (j = 1; j<4; j++) {
if (min[i]>array[i][j])/
min[i] = array[i][j];
}
}
``````

But I do not know if this code is correct.
(I guess it is not.) I dont know how to extract them(minimum elements).

And with this i will try to make new array:

``````for(i = 0; i < 4; i++) {
for(j = 0; j < 4; j++) {
newarr[i][j]=array[i][j];
newarr[i][5]=max[i];
}
}

for(j = 0; j < 4; j++)
newarr[5][j]=min[j];
``````

Is this okay? There is no way to check it because I just can not find the min and max.

I think you may be overthinking this a bit. A 5X5 array contains a 4X4 array in it, just use indexes 0-3. Leave the index 4 for the min and max values. Now everything, entering the data, finding the min values, and finding the max values, can be done in the initial nested loop:

``````int data[5][5];
//This seeds the min and max with start values
for (int i = 0; i < 5; i++)
{
data[i][4] = INT_MAX;
data[4][i] = INT_MIN;
}
int i, j;
for(i = 0; i < 4; i++) {
for(j = 0; j < 4; j++) {
cout << "\n data[" << i + 1 << "][" << j + 1 <<"]=";
cin >> data[i][j];
//check if the new value is less than the current min value for that row
if (data[i][j] < data[i][4])
{
data[i][4] = data[i][j];
}
//Check if the new value is greater than the current max value for that column
if (data[i][j] > data[4][j])
{
data[4][j] = data[i][j];
}
}
}
``````

On side note try not to use keywords for variable names. This is very bad form and can lead to unpleasant complications.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.