. Повернутися

int PosFirstMaxDig(int n)
{
    if (n<=0) return -1;
    int maxDigit=0, position=0, currentPos=0;
    int temp=n;
    while (temp>0)
    {
        currentPos++;
        temp/=10;
    }
    while (n>0)
    {
        int digit=n%10;
        if (digit>=maxDigit)
        {
            maxDigit=digit;
            position=currentPos;
        }
        n/=10;
        currentPos--;
    }
    return position;
}