我的C程序无法正常工作。我试图从用户和一个基数中获取一个正数,并将其转换为二进制。基数只能在2-6之间。我无法获取正确的二进制值。我已在下面复制了我的代码,如果您看到任何错误或知道为什么我没有得到正确的答案,请帮助我。
#define MIN_BASE 2
#define MAX_BASE 16
int main()
{
//Variale Declarations
int num;
int base;
int binary;
int remainder;
int i;
printf("Enter a positive number: ");
scanf("%d", &num);
printf("Enter a base: ");
scanf("%d", &base);
if (base >= MIN_BASE && base <= MAX_BASE) {
while( num > 0){
remainder = num % base;
num = num / base;
binary = remainder, binary;
}
}
else {
while(base < MIN_BASE || base > MAX_BASE){
printf("!! The base is invalid!!\n");
printf("Enter a base: ");
scanf("%d", &base);
}
}
printf("%d\n", binary);
return 0;
}