#include <stdio.h>
#include <math.h>
long toBinary(int num);
int main(int argc, char const *argv[])
{
int num;
printf("Please input a number: ");
scanf("%d", &num);
long binnary = toBinary(num);
printf("%d\n", binnary);
return 0;
}
long toBinary(int num) {
short count = 0;
short i;
long ret = 0;
short nums[64];
while(num) {
nums[count++] = num % 2;
num = num / 2;
}
for(i = count - 1; i >= 0; i--) {
ret += pow(10, i) * nums[i];
}
return ret;
}
标签:short,进制,nums,int,long,C语言,num,ret,十进制
From: https://www.cnblogs.com/anas-kai/p/17045033.html