To get the decimal digit at position p
integer i
, you do the following:
(i / pow(p, 10)) % 10;
So, to iterate over the last digit in the first digit, you must do the following:
int n = 56; // 056 int digit; while(n) { digit = n % 10; n /= 10; // Do something with digit }
Easy to change to do it exactly 3 times.
source share