进制转换

#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;

}

  

posted @ 2012-02-22 19:41  我的小花篮  阅读(118)  评论(0编辑  收藏  举报