关闭

实现数据的反序

标签: 反序
206人阅读 评论(0) 收藏 举报
分类:

数的反序
题目:
输入整数 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;
}
}
}

0
0

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