Code:
void binary(int number)
{
int i, count, temp = number;
for(count = 0; number > 0; count++)
{
number /= 2;
}
number =temp; // try saving the input.. else you would have lost it in the first loop.
int * remainder = calloc(count, sizeof(int)); //to get around your compiler //incompatibility. should use free though as stated.
for(i = 0; i < count; i++)
{
remainder[i] = number % 2;
printf("%d\t",remainder[i]);
number /= 2;
printf("%d\t", number);
printf("%d\n\n", i);
}
for(i = count - 1; i >= 0; i--) // introduce a -1 here prints an extra zero..
printf("%d", remainder[i]);
}
hope this helps..
Nitin