Returning a single character from a string, returns as a int?(bit operate
#6

Sure thing:
pawn Код:
stock FirstDigit(n) {
    new
        digit = 0;
       
    //First thing - get the absolute value of n
    //(in fact that's a little better version)
    if(n < 0) n = -n;

    do {
        //Get the modulus of n, returning last digit
        //(we can't jump straight to first though :c)
        //So for 1245 it will be 5
        digit = n % 10;
       
        //Remove last digit (it's an integer, so it doesn't have fractions - insta flooring)
        //1245 => 124
        n /= 10;

        //Do so until there are no more digits left
    } while (n > 0);
   
    return digit;
}
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 3 Guest(s)