Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- const int MAX = 5;
- int main() {
- int pila[MAX];
- int tope = 0;
- int elemento;
- // Insertar 5 elementos en la pila
- for (int i = 0; i < MAX; i++) {
- cout << "Introduce el elemento " << (i + 1) << ": ";
- cin >> elemento;
- if (tope < MAX) {
- pila[tope] = elemento;
- tope++;
- } else {
- cout << "La pila está llena." << endl;
- }
- }
- // Mostrar y eliminar los elementos de la pila
- while (tope > 0) {
- tope--;
- cout << "Elemento eliminado: " << pila[tope] << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement