#include<iostream>
using namespace std;
void convert(int n,int base,char a[]){
int i=0;
while(n>0){
if(base<10||n%base<10){
a[i++]=n%base+'0';//填空
}
else{
a[i++]=n%base+'A'-10;//填空
}
n=n/base;
}
a[i]='\0';
}
void print(char a[]){
int i=0,j=0,temp=0;
while(a[j])j++;
j=j-1;//填空
for(;i<j;i++,j--){//填空
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
cout<<"结果:"<<a;
}
int main(){
int number,base;
char a[20];
cin>>number>>base;
convert(number,base,a);//填空
print(a);
return 0;
}
运行结果
123 2
结果:1111011
--------------------------------
Process exited after 3.178 seconds with return value 0
请按任意键继续. . .
123 16
结果:7B
--------------------------------
Process exited after 3.909 seconds with return value 0
请按任意键继续. . .