#include <stdio.h> #include <stdint.h> void print_hex(uint16_t num) { // Your logic here char res[20]; int i = 0; if(num == 0){ putchar('0'); return; } while(num > 0){ int d = num % 16; if(d < 10){ res[i] = d + '0'; } else{ res[i] = (d - 10) + 'A'; } num /= 16; i++; } while(i > 0){ printf("%c", res[--i]); } } int main() { uint16_t num; scanf("%hu", &num); print_hex(num); return 0; }
Test Cases
Test Results
Input
255
Expected Output
FF