#include <stdio.h> #include <stdint.h> void print_hex(uint16_t num) { // Buffer for up to 4 hex digits (+1 for '\0' if needed) char buf[5]; // Special case for zero if (num == 0) putchar('0'); int i = 0; // Extract hex digits (from LSB) while (num > 0) { uint8_t digit = num % 16; if (digit < 10) buf[i] = '0' + digit; else buf[i] = 'A' + (digit - 10); num /= 16; i++; } // Print in reverse order (from MSB) for (int j = i - 1; j >= 0; j--) putchar(buf[j]); } int main() { uint16_t num; scanf("%hu", &num); print_hex(num); return 0; }
Test Cases
Test Results
Input
255
Expected Output
FF