I have an assignment to convert a number from decimal to binary. My problem is that I need to have it printed out directly from the function, instead of returning it back to main. Due to this, my printed out code is in the wrong order. (ex: for 6, my code prints out 011 instead of 110)
This is what I have been using for the function:
int printBinary(int integer) {
int remainder;
if (integer < 1) {
return 0;
} else {
remainder = integer % 2;
printf("%d", remainder);
integer = integer / 2;
printBinary(integer);
return 0;
}
}
Does anyone have a suggestion on how I can print it out in reverse, or a different approach entirely?