张麻子


私信TA

用户名:qwezjh

访问量:2475

签 名:

上任鹅城

等  级
排  名 838
经  验 3499
参赛次数 0
文章发表 25
年  龄 0
在职情况 学生
学  校 asd
专  业

  自我简介:

TA的其他文章

解题思路:

注意事项:

参考代码:

#include "stdio.h"

int main() 

{

int ten; int two[100];

while (scanf("%d", &ten) != EOF) 

{

printf("%d-->", ten);

if (ten == 0) { printf("0"); printf("\n"); continue; }

if (ten < 0) 

{

ten = -1 * ten;

int k = 0;

while (1)

{

if (ten == 0) { break; }

two[k] = ten % 2; k++;

ten = ten / 2;

}

printf("-");

for (int i = k - 1; i >= 0; i--) { printf("%d", two[i]); } printf("\n");

continue;

}

int k = 0;

while (1) 

{

if (ten == 0) { break; }

two[k] = ten % 2; k++;

ten = ten / 2;

}

for (int i = k-1; i >=0; i--) { printf("%d", two[i]); } printf("\n");

}

}


 

0.0分

0 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区