2025-03-06 22:46:33 +08:00

22 lines
509 B
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*-------------------------------------------------------
从键盘输入一个十进制整数将其转换为二进制后反序再转成新的十进制后输出。11→1011→1101→13使用while循环
-------------------------------------------------------*/
#include <stdio.h>
main()
{
int n,s,t;
s=0;
printf("请输入一个整数:");
scanf("%d",&n);
/**********Program**********/
//1011 从最末尾开始 依次除出
//加入s之前将前加入的数*1
while(n){
s += s + n%2;
n /= 2;
}
/********** End **********/
printf("%d\n",s);
}