#include <stdio.h> #include <stdint.h> void print_base(uint16_t num, uint8_t base) { if (num==0){ printf ("0"); return; } char buffer[16]; int i = 0; char hex_chars[] = "0123456789ABCDEF"; while (num>0) { int remainder = num % base; buffer[i++] = hex_chars[remainder]; num/=base; } for (int j = i-1; j >= 0; j--) { printf ("%c", buffer[j]); } } int main() { uint16_t num; uint8_t base; scanf("%hu %hhu", &num, &base); print_base(num, base); return 0; }
Test Cases
Test Results
Input
10 2
Expected Output
1010