Settings | Sign in | Sign up

There is currently 1 post.

【试题】十进制转十六进制

Floor 1 巨大八爪鱼 3/3/16 17:52
#include <stdio.h>

char *tpl = "0123456789ABCDEF";

int main()
{
    int num;
    char buffer[20];
    char *pBuf;
    scanf("%d", &num);
    if (num == 0)
        puts("0");
    else
    {
        buffer[19] = '\0';
        for (pBuf = buffer + 18; num > 0; pBuf--)
        {
            *pBuf = tpl[num & 0x0f];
            num >>= 4;
        }
        puts(pBuf + 1);
    }
    return 0;
}

Content converter:

Reply the post
Content:
User: You are currently anonymous.
Captcha:
Unclear? Try another one.