hi,
i need a little help. i have a 2d array adn i want to write out each rows minimum number. but something isnt good cause if the minimum is in the last position it says that the first number is the lowest.
heres the code:

void minki(int k,int n, int m, int x[maxn][maxm])
{
    int a[n];
    int l=0;

    for (int i=0; i<n; ++i)
        {
            int b=x[i][0];
            for (int j=0; j<m; ++j)
            {
                
                if (b>x[i][j])
                {
                    l=x[i][j];
                    j++;
                }
                if (b<x[i][j])
                {
                    ++j;
                }
                else {l=x[i][0];
            }
            a[i]=l;

        cout << "test " << a[i] << endl;
        }
}

here is the array:
1 42 23 14
2 23 41 15
3 63 17 18
4 3 24 15
5 32 42 13
6 34 56 78
7 22 32 4
8 35 46 3

the problem:
if the last number is the lowest then l=x[j] and the program add +1 to j=3 m=4 so 3+1=4 4!<4 so why increase the program if it isnt allowed?

Do not change j inside your loop.

All you need to do in the inner j loop is:
1) Compare b with the current x value (you are doing this)
2) If less than, replace b with the current x value.
That's it.

here is the array:
1 42 23 14
2 23 41 15
3 63 17 18
4 3 24 15
5 32 42 13
6 34 56 78
7 22 32 4
8 35 46 3

the problem:
if the last number is the lowest then l=x[j] and the program add +1 to j=3 m=4 so 3+1=4 4!<4 so why increase the program if it isnt allowed?

First, I think you need to pay closer attention to you naming convention. The variable names 'k', 'm', 'n', 'x', and 'a' are completely meaningless. What are they intended to represent. There is no good way to discern that information from the snippet provided.

Let me make sure I understand your question. The "matrix" is a 3x8 matrix declared as such:

const int ROWS = 8, COLS = 3;
int theMatrix[ROWS][COLS];

and populated as indicated.

What you are attempting to do is find the lowest value in each row. So for example, if Row 1 is 42 23 14 , you want it to find the 14. Is that correct?

Also, what is 'k' for? I can't see where you've even used it in your function.

EDIT:
Oops, hey Walt :) Good point about 'j'. I hadn't looked at it that closely yet...

thank u all :) its workink perfectly :)

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.