#include <iostream>
#include <stack> 

using namespace std;

int main() {
    int numero_decimal;
    stack<int> pila_binario;

    cout << "Ingresa un número decimal: ";
    cin >> numero_decimal;

    if (numero_decimal < 0) {
        cout << "Por favor, ingresa un número entero no negativo." << endl;
        return 1; 
    }

    if (numero_decimal == 0) {
        cout << "El equivalente en binario es: 0" << endl;
    } else {
        while (numero_decimal > 0) {
            pila_binario.push(numero_decimal % 2);
            numero_decimal /= 2;
        }

        cout << "El equivalente en binario es: ";
        while (!pila_binario.empty()) {
            cout << pila_binario.top();
            pila_binario.pop();
        }
        cout << endl;
    }

    return 0;
}

Embed on website

To embed this program on your website, copy the following code and paste it into your website's HTML: