hello there, I am working on a small c program that automatically detects whether the input given is a decimal number or a binary number and coverts accordingly.
what is the best way to convert a binary number to a decimal number and a decimal number to a binary number.
i found this to be the easiest when converting from binary to deicmal
http://www.wikihow.com/Convert-from-Decimal-to-Binary
but my program doesnt work..?
/*decimal to binary*/
#include <stdio.h>
int main() {
int dec;
int hold=0;
printf("decimal number : ");
scanf("%d",&dec);
hold=dec%2;
while (hold!=1){
if (hold == 0){
printf("0");
}else if(hold >1){
printf("1");
}else{
printf("1");
}
hold=hold%2;
}
}
what have i done wrong?