Ad
  • Default User Avatar

    Variable n contains the number of digits of the input number, it is incremented in digits[n++] = number % 10; .
    The comparison in the later loop is between the current iteration aka digit with the total digits n (minus 1 because i starts at 0) and divided by two because you are "cutting" the input number in two halfs: the left and the right one, so your sums will be only between the n/2 digits from each side.
    The left digits sum is performed from left to right (hence sumLeft += digits[i]) and the right digits sum is performed from right to left (hence sumRight += digits[n-i-1] -- note the n-i subtraction).