-
parsing a number
to parse a number using modulus and division
would you do this
for example ( number = 12345 )
Code:
digit1 = ( number % 10 ) /1; /*5*/
digit2 = ( number % 100 ) / 10; /*4*/
digit3 = ( number % 1000 ) / 100; /*3*/
digit4 = ( number % 10000 ) / 1000; /*2*/
digit5 = ( number % 100000 ) / 10000; /*1*/
the digits are integers so the decimals get truncated
is there way another to parse the number using modulus and division
-
:-)
Code:
#include <stdio.h>
int main(void)
{
int a = 12345;
do
{
printf("%d\n", a % 10);
}
while (a /= 10);
return 0;
}