编程实现将任意的十进制整数转换成任意R进制数(R在2-16之间)。(C语言)
#include <stdio.h>
int main(){
int number = 0;
int digital = 0;
int count = 0;
int temp = 0;
printf("请输入10进制数:");
scanf("%d", &number);
printf("请输入要转化的进制数:");
scanf("%d", &digital);
int a[100] = {0};
char b[6] = "ABCDEF";
while(number){
temp = number % digital;
number /= digital;
a[count] = temp;
count++;
}
for(int i = count - 1; i >= 0; i--){
if(a[i] < 10) printf("%d",a[i]);
else{
printf("%c", b[a[i] % 10]);
}
}
return 0;
} |