Code of putnbr, I can't display 0
newbeeC
-
ydurce Posted messages 81 Status Membre -
ydurce Posted messages 81 Status Membre -
Hello,
I have a small algorithm problem; in class I need to recode the function putnbr. I'm almost there, except that it doesn't handle when the parameter is 0. Does anyone have an idea?
int my_put_nbr(int nb)
{
if (nb < 0)
{
my_putchar('-');
nb = -nb;
}
if (nb == 0)
return;
my_put_nbr(nb / 10);
my_putchar(nb % 10 + '0');
}
Configuration: Windows 7 / Firefox 3.6.11
I have a small algorithm problem; in class I need to recode the function putnbr. I'm almost there, except that it doesn't handle when the parameter is 0. Does anyone have an idea?
int my_put_nbr(int nb)
{
if (nb < 0)
{
my_putchar('-');
nb = -nb;
}
if (nb == 0)
return;
my_put_nbr(nb / 10);
my_putchar(nb % 10 + '0');
}
Configuration: Windows 7 / Firefox 3.6.11