Get varialbe max value
#1

Hi how to know which variable value is biggest for ex:

Код:
new VARIABLESNEW[ 6 ];

VARIABLESNEW[ 0 ] = 10;
VARIABLESNEW[ 1 ] = 5;
VARIABLESNEW[ 2 ] = 7;
VARIABLESNEW[ 3 ] = 3;
VARIABLESNEW[ 4 ] = 15;
VARIABLESNEW[ 5 ] = 2;
Of course varialbes value will be different. But now looking to this example biggest variable is 4

VARIABLESNEW[ 4 ]

But now, how just know which variable is with biggest value?
Reply
#2

pawn Код:
stock minArray(arr[], len = sizeof arr) {
    new
        record = cellmin,
        index = -1
    ;
    for(new i = 0; i != len; ++i) {
        if(arr[i] > record) {
            index = i;
            record = arr[i];
        }
    }

    return index;
}

//(...)
new
    result = minArray({ 5, 6, 8, 14, 14, 10 }, 6)
;
//result == 3
This will return first index with highset value (if indexes 3 and 4 have maximum value, function will return 3). Also, it will return -1 if all your cells contain cellmin value.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)