实现数据的反序

数的反序
题目:
输入整数 x 和进制 R,输出 x 的 R 进制反序数。
例子:
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;
}
}
}

阅读更多
文章标签: 反序
个人分类: C/C++编程
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

不良信息举报

实现数据的反序

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭