Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- const char digitmap[] = "0123456789abcdef";
- char *num_to_s(int val, int base) {
- char *ret = (char *)malloc(BUFSIZ);
- ret = ret + BUFSIZ;
- *--ret = '\0';
- do {
- *--ret = digitmap[(int )(val % base)];
- } while (val /= base);
- return ret;
- }
- int main(void) {
- int val, base;
- printf("number base ? ");
- scanf("%d%d", &val, &base);
- printf("%d base %d = %s\n", val, base, num_to_s(val, base));
- return EXIT_SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement