Code:
int N_DISPLAY = 4;
int digitos[4];
int v_digito = 7653;
int i;
for (i=N_DISPLAY-1 ; i>=0 ; i--)
{
digitos[i] = v_digito/(int)pow(10.0, (double)i);
printf("%ld\n", digitos[i]);
v_digito = v_digito - digitos[i]*(int)pow(10, (double)i);
printf("%ld\n",v_digito);
}
This is what I run and the answer seems to be fine...
Could you explain further what is the problem?
Code:
My answer:
7
653
6
53
5
3
3
0
also tried the following variations and everything seems ok.
Code:
digitos[i] = (int) ((double)v_digito/pow(10.0, (double)i));
v_digito = v_digito - digitos[i]*pow(10, (double)i);
;
In the second expression, there is no necessity of casting.
Regards