#include <iostream>
using namespace std;
#define max 100
int s[max],top=-1,n;

void create(){
    int x;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>x;
        if(top==n)
        {
            cout<<"Ovrflow";
        }
        else
        {
            top+=1;
            s[top]=x;
        }
    }
}

void insert(int val){
    if(top==max){
        cout<<"Can't insert\n";
    }
    else{
        top=top+1;
        s[top]=val;
    }
}

void print(){
    int y = top;
    while(y != -1){
        cout<<s[y--]<<"\n";
    }
}

void pop(){
    if(top==-1){
        cout<<"Underflow\n";
    }
    else{
    top-=1;
    }
}

int main() {
    create();
    cout<<"Stack created\n";
    print();
    pop();
    cout<<"poped top element\n";
    print();
    insert(10);
    cout<<"Inserted element 10\n";
    print();
    return 0;
}

Embed on website

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