#include <stdio.h>
#define N 5
int stack[N];
int top=-1;
void push()
{
    int x;
    printf("enter the data: ");
    scanf("%d",&x);
    if(top=N-1)
    {
        printf("OVERFLOW");
    }
    else 
    {
        top++;
        stack[top]=x;
    }
}
void pop()
{
    int i;
    if(top==-1)
    {
        printf("UNDERFLOW");
    }
    else
    {
        i=stack[top];
        top--;
        printf("Poped elements are : %d",stack[i]);
        
    }
}
void display()
{
    int a;
    if(top==-1)
    {
        printf("The Stack is empty");
    }
    else
    {
        for(a=top;a>=0;a--)
        {
            printf(" %d",stack[a]);
        }
    }
}
void peek()
{
    if(top==-1)
    {
        printf("The stack has no element");
    }
    else
    {
        printf("The peek element is: %d",stack[top]);
    }
}
void main()
{
    int ch;
    do
    {
    printf("1.PUSH\n2.POP\n3.DISPLAY\n4.PEEK : ");
    scanf("%d",&ch);
    
    switch(ch)
    {
        case 1: push();break;
        case 2: pop();break;
        case 3: display();break;
        case 4: peek();break;
    }
    }
    while(ch!=0);
}

Embed on website

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