Return max, and repeating from string array.
#2

pawn Код:
ReturnMax(&count, const string[], len)
{
    count = 0;
    new max_val = -1;
   
    for (new i; i != len; ++i)
    {
        if (string[i] > max_val)
        {
            max_val = string[i];
            count = 1;
        }
        else if (string[i] == max_val) ++count;
    }
    return max_val;
}
An example:
pawn Код:
test[0] = 44;
test[1] = 11;
test[2] = 44;

new
    count,
    value = ReturnMax(count, test, sizeof (test));
   
printf("%i %i", count, value);
It will print 2 (2 indexes with the highest number) and 44 (the highest number).
Reply


Messages In This Thread
Return max, and repeating from string array. - by [WSF]ThA_Devil - 15.06.2014, 15:45
Re: Return max, and repeating from string array. - by Konstantinos - 15.06.2014, 16:17
Re: Return max, and repeating from string array. - by [WSF]ThA_Devil - 15.06.2014, 17:27

Forum Jump:


Users browsing this thread: 1 Guest(s)