C++中十进制转换成二进制代码
时间: 2023-05-28 18:03:16 浏览: 122
c++十进制转换二进制
5星 · 资源好评率100%
#include <stdio.h>
int main() {
int num, binary = 0, base = 1;
printf("Enter a decimal number: ");
scanf("%d", &num);
while (num > 0) {
binary += (num % 2) * base;
num /= 2;
base *= 10;
}
printf("Binary equivalent: %d", binary);
return 0;
}
阅读全文