十进制(0~2147483647)转任意进制(2进制~16进制)。

ぃ、小莉子 提交于 2020-03-09 04:46:57
#include <stdio.h>

void main() {
    int num, radix, i = 0;
    char res[32] = {'0'}, table[] = "0123456789ABCDEF";
    printf("Please enter the value to be converted:");
    scanf("%d", &num);
    printf("Please enter the radix to be converted:");
    scanf("%d", &radix);
    if (num == 0)
        i = 1;
    while (num > 0) {
        res[i++] = table[num % radix];
        num = num / radix;
    }
    printf("Result:");
    while (--i >= 0)
        printf("%c", res[i]);
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!