.
Повернутися
int PosLastMaxDig(int n)
{
if (n<=0) return -1;
int maxDigit=-1, position=0, currentPos=0;
int temp=n;
while (temp>0)
{
currentPos++;
temp/=10;
}
currentPos=0;
while (n>0)
{
int digit=n%10;
currentPos++;
if (digit>maxDigit)
{
maxDigit=digit;
position=currentPos;
}
n/=10;
}
return position;
}
|