#include<stdio.h> #define N 8 #define k 16 void tran(int num) { int arr[N],i; for (i=0;i <N;i++) { arr[i]=num%k; num=num/k; if (num==0) break; } printf("转换为%d进制数为: ",k); for (;i>=0;i--) switch (arr[i]) { case 10: printf("A");break; case 11: printf("B");break; case 12: printf("C");break; case 13: printf("D");break; case 14: printf("E");break; case 15: printf("F");break; default: printf("%d",arr[i]); } printf("\n"); } int main() { int num; printf("请输入要转换的十进制数:\n"); scanf("%d",&num); tran(num); return 0; }
转载于:https://blog.51cto.com/8887511/1406070