#include #include #include

using namespace std;

int main() { int decimal; cout << "Enter a decimal number: "; cin >> decimal;

// Convert decimal to hexadecimal
stack<char> hexStack;
while (decimal > 0) {
    int remainder = decimal % 16;
    if (remainder < 10) {
        hexStack.push(remainder + '0');
    } else {
        hexStack.push(remainder - 10 + 'A');
    }
    decimal /= 16;
}

// Print hexadecimal number
cout << "Hexadecimal number is: ";
while (!hexStack.empty()) {
    cout << hexStack.top();
    hexStack.pop();
}
cout << endl;

return 0;

}

十进制转换十六进制c++代码

原文地址: https://www.cveoy.top/t/topic/Mgb 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录