I have an integer:
int iNums = 12476;
and I want to get each digit from it as an integer. Something like:
foreach(iNum in iNums){
printf("%i-", iNum);
}
So the output would be:
1-2-4-7-6-
But I need each digit as an int
not as char
.
int iNums = 12345;
int iNumsSize = 5;
for (int i=iNumsSize-1; i>=0; i--) {
int y = pow(10, i);
int z = iNums/y;
int x2 = iNums / (y * 10);
printf("%d-",z - x2*10 );
}