发布网友 发布时间:2022-05-31 13:05
共2个回答
热心网友 时间:2023-10-15 14:39
#include #define LEN 100char *decimal2Others (int value, char *string, int radix) { /*十进制数转任意进制*//*除基数取余法:十进制数不断除以进制基数直至为零,每次相除取得余数之逆序即为转换结果*/ int remain,i=1,j=0; int temp[LEN]; while (value) { /*除基数取余*/ remain = value % radix; value = value / radix; temp[i++] = remain; } while (--i) { /*逆序存储*/ if (temp[i] > 9) string[j++] = temp[i] - 10 + 'a'; /*十以上进制处理*/ else string[j++] = temp[i] + '0'; } string[j] = '\0'; return string;}int main(void) { int n; char string[LEN]; printf ("请输入十进制数:"); scanf ("%d",&n); putchar ('\n'); puts ("================================================================================\n"); printf ("十六进制转换结果:"); decimal2Others (n,string,16); puts (string); putchar ('\n'); getch (); /*屏幕暂留*/ return 0;} 运行结果热心网友 时间:2023-10-15 14:40
#include<stdio.h>