您的位置:首页 > 其它

进制转换

2012-02-22 19:41 120 查看
#include<stdio.h>
#include<math.h>

int main()
{
int a[100];
int n,r,i,temp,loop,temp_1;

while(scanf("%d%d",&n,&r)!=EOF)
{
temp_1=n;
loop=1;
i=0;

do
{
int temp;

temp=n%r;
a[i++]=abs(temp);
}while((n/=r)!=0);

for(temp=i-1;temp>=0;temp--)
{
if(temp_1<0&&loop==1)
{
printf("-");
loop=0;
}

if(a[temp]<10)
{
printf("%d",a[temp]);
}
else
{
printf("%c",55+a[temp]);
}
}
printf("\n");
}
return 0;

}


  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: