文章
10
粉丝
17
获赞
0
访问
3.9k
#include<bits/stdc++.h>
using namespace std;
void decimal_to_binary(char s[]){
char out[105];
int len = strlen(s);
int k = 0;
while(len){
//用最后一位数字计算余数
out[k++] = (s[len - 1] - '0') % 2 + '0';
//处理除法
int carry = 0;
for (int i = 0; i < len; i++) {
int current = (s[i] - '0') + carry * 10;
s[i] = (current / 2) + '0';
carry = current % 2;
}
//去除多余的前导0
if (s[0] == '0'){
&n...
登录后发布评论
暂无评论,来抢沙发