题目描述 Description
将十进制数n转换成m进制数 m<=16
n<=100
输入描述 Input Description
共一行
n和m
输出描述 Output Description
共一个数
表示n的m进制
样例输入 Sample Input
样例1:10 2
样例2:100 15
样例输出 Sample Output
样例1:1010
样例2:6A
数据范围及提示 Data Size & Hint
用反向取余法
#include <iostream>
using namespace std;
int main()
{
int n,m,index=0;
char Array[100];
cin>>n>>m;
while(n!=0)
{
int temp=n%m;
if(temp<10)Array[index++]=temp+'0';
else if(temp==10) Array[index++]=temp%10+'A';
n=n/m;
}
for(--index;index>=0;index--)
cout<<Array[index];
cout<<endl;
return 0;
}