hi there people
i got a prob with my code
in my problem i got a matrix and i need to find the even number or numbers on that matrix (12x30) (by the way is the even minimun or minimums), so here is my function "tempeven" part., the actual issue is that is printing the 3 minimun even numbers, and sometimes is not printing anything.

``````void Tempeven(int X[][col])
{
int cont=0;
cout<<"the temperaturas even min: "<<endl;
int min=X[0][0];
for (int i=0;i<row;i++)
{
for (int j=0;j<col;j++)
{

if (X[i][j]%2 == 0 && X[i][j]<min)

min=X[i][j];
cout<<endl<<min;

}
}

}
``````
3
Contributors
3
Replies
27
Views
3 Years
Discussion Span
Last Post by jarleking

If you move the ouptut statement outside of the for loops, then you should always print out the lowest value in the matrix.

If you want to out put the three lowest even values in the matrix then there are a variety of options. One approach would be to sort the matrix, then output the first three even numbers.

Just shift the output statement to the end of the outer for loop if you want to display the minimum even no. of each row

``````void Tempeven(int X[][col])
{
int cont=0;
cout<<"the temperaturas even min: "<<endl;
int min=X[0][0];
for (int i=0;i<row;i++)
{
for (int j=0;j<col;j++)
{
if (X[i][j]%2 == 0 && X[i][j]<min)
min=X[i][j];

}
cout<<endl<<min; }
}
``````

else you can also move the output statement to the end of both the for loops and then you will see the minimum even no. of the matrix

``````void Tempeven(int X[][col])
{
int cont=0;
cout<<"the temperaturas even min: "<<endl;
int min=X[0][0];
for (int i=0;i<row;i++)
{
for (int j=0;j<col;j++)
{
if (X[i][j]%2 == 0 && X[i][j]<min)
min=X[i][j];

}
cout<<endl<<min; }
``````