#include
void main()
{
int n,right_digit,sum=0,count=0;
scanf("%d",&n);
do
{
right_digit=n%2;
sum=sum*2+right_digit;
n=n/2;
count++;
}
while(n!=0);
printf("%d",sum);
printf("\n");
do
{
right_digit=sum%2;
printf("%d",right_digit);
sum=sum/2;
count--;
}
while(sum!=0||count>0);
printf("\n");
}
另一个改的版本
#include
void main()
{
int n,right_digit,sum=0,count=0;
scanf("%d",&n);
do
{
right_digit=n%2;
sum=sum*10+right_digit;
n=n/2;
count++;
}
while(n!=0);
printf("%d",sum);
printf("\n");
do
{
right_digit=sum%10;
printf("%d",right_digit);
sum=sum/10;
count--;
}
while(sum!=0||count>0);
printf("\n");
}
这两种都是的,但是含义不太一样