# 实现数据的反序

206人阅读 评论(0)

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:
{
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:
{
while(a != 0)
{
t = a%16;
a = a/16;
printf(“%d”,t);
}
printf(“\n”);
break;
}
}
}

0
0

* 以上用户言论只代表其个人观点，不代表CSDN网站的观点或立场
个人资料
• 访问：4740次
• 积分：228
• 等级：
• 排名：千里之外
• 原创：19篇
• 转载：0篇
• 译文：0篇
• 评论：0条
阅读排行
评论排行