#include<stdio.h>
int main(){
char c[30]="0123456789ABCDEF";
int a[10];
int M,N;
printf("请输入M的值:");
scanf("%d",&M);
printf("请输入N的值:");
scanf("%d",&N);
int i=0;
if(N>=2&&N<=16){
while(M!=0){
a[i++]=M%N;
M=M/N;
}
for(int j=i-1;j>=0;j--){
int s=a[j];
printf("%c",c[s]);
}
}else{
printf("请输入n的值在2-16之间");
}
getchar();
getchar();
}
输入2个二进制数m和n,输出m对应的n进制数,2<=n<=16
![](https://img-home.csdnimg.cn/images/20240711042549.png)