#include<iostream> #include<string> using namespace std; int main() { int a;//輸入的數 int y = 0;//循環中的余數' string s = ""; cin >> a; if (a == 0)//比較特殊,單獨處理 { cout << 0; return 0; } while (a > 0)//大於0的數 { y = a % 16;//求余 if (y < 10)//小於10的余數 { s = char('0' + y) + s; } else { s = char('A' - 10 + y) + s; } a = a / 16; } cout << s; return 0; }