# 实现数据的反序

X:123 R:10 输出：321
X:-123 R:10 输出：-321
X:123 R:8 输出：371

void Signed(int ,int );
void Unsigned(int ,int );

int main()
{
int a,i;
printf(“Input the number:”);
scanf(“%3d”,&a);
printf(“Input the number system(2¡¢8¡¢10 or 16):”);
scanf(“%2d”,&i);
if(a == 0)
{
printf(“NO PROCESS!\n”);
return;
}
if(a != abs(a)) //输入数据为负数
Signed(a,i);
else
Unsigned(a,i);
return 0;
}

void Unsigned(int a,int i)
{ int t;
switch(i)
{
case 2:
{
printf(“The Binary inversion number is:”);
while(a != 0)
{
t = a%2;
a = a/2;
printf(“%d”,t);
}
printf(“\n”);
break;
}
case 8:
{
printf(“The Octal inversion number is:”);
while(a != 0)
{
t = a%8;
a = a/8;
printf(“%d”,t);
}
printf(“\n”);
break;
}
case 10:
{
printf(“The Decimal inversion number is:”);
while(a != 0)
{
t = a%10;
a = a/10;
printf(“%d”,t);
}
printf(“\n”);
break;
}
case 16:
{
printf(“The Hexadecimal inversion number is:”);
while(a != 0)
{
t = a%16;
a = a/16;
printf(“%d”,t);
}
printf(“\n”);
break;
}
}
}

void Signed(int a,int i)
{
int t;
a = abs(a);
switch(i)
{
case 2:
{
printf(“The Binary inversion number is:-“);
while(a != 0)
{
t = a%2;
a = a/2;
printf(“%d”,t);
}
printf(“\n”);
break;
}
case 8:
{
printf(“The Octal inversion number is:-“);
while(a != 0)
{
t = a%8;
a = a/8;
printf(“%d”,t);
}
printf(“\n”);
break;
}
case 10:
{
printf(“The Decimal inversion number is:-“);
while(a != 0)
{
t = a%10;
a = a/10;
printf(“%d”,t);
}
printf(“\n”);
break;
}
case 16:
{
printf(“The Hexadecimal inversion number is:-“);
while(a != 0)
{
t = a%16;
a = a/16;
printf(“%d”,t);
}
printf(“\n”);
break;
}
}
}

• 本文已收录于以下专栏：

举报原因： 您举报文章：实现数据的反序 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)