I'm trying to convert decimal to binary via this program, but the output is always missing the last digit.
For example, I'll input "123" for quotient, and the result will be "111101" instead of "1111011". This happens for every input I test. Every digit is in the right place, except for the last one, which is missing.
Any help would be appreciated.
#include <stdio.h>
int main ()
{
int quotient = 123;
int i = 0;
int d1 = quotient % 2;
quotient = quotient / 2;
int c = 0;
int a = 0;
int number[32] = {};
while (quotient != 0)
{
i = i+1;
d1 = quotient % 2;
quotient = quotient / 2;
c++;
number[c]=d1;
}
for(a = 0; a < c; a = a + 1 )
{
printf("%d", number[c-a]);
}
return 0;
}