进制转换

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

}

  

原文地址:https://www.cnblogs.com/deosky/p/2363684.html