Downloaded 80 times

![The Main Module
#include<stdio.h>
#include<stdlib.h>
void push(), pop(), display();
int top=-1,stack[5];
int main()
{
int choice;
while(1)
{
printf("n----Stack Menu----n");
printf("1. Push.n");
printf("2. Pop.n");
printf("3. Display.n");
printf("4. Exit.n");
printf("Enter your choice: ");
scanf("%d",&choice);
switch(choice)
{
case 1: push();
break;
case 2: pop();
break;
case 3: display();
break;
case 4: exit(0);
break;
default: printf("Invalid option.");
}
}
}](https://image.slidesharecdn.com/stackusingarray-160303131915/75/Stack-using-Array-2-2048.jpg)
![Insert An Element Into Stack
void push()
{
if(top<4)
{
int num;
printf("Enter an integer value: ");
scanf("%d",&num);
top++;
stack[top]=num;
}
else
{
printf("nStack Overflow.n");
}
display();
}](https://image.slidesharecdn.com/stackusingarray-160303131915/75/Stack-using-Array-3-2048.jpg)
![Delete An Element From Stack
void pop()
{
if(top>=0)
{
printf("Item popped is: %d",stack[top]);
top--;
}
else
{
printf("nStack Underflow.n");
}
display();
}](https://image.slidesharecdn.com/stackusingarray-160303131915/75/Stack-using-Array-4-2048.jpg)
![Display The Elements In Stack
void display()
{
int head=top;
if(head>=0)
{
printf("The items in the stack are: ");
while(head!=-1)
{
printf("n%d",stack[head]);
head--;
}
}
else
{
printf("nStack empty.n");
}
}](https://image.slidesharecdn.com/stackusingarray-160303131915/75/Stack-using-Array-5-2048.jpg)

This document describes an implementation of a stack using an array in C. It includes functions to push elements onto the stack, pop elements off the stack, and display the elements currently in the stack. The main module contains a menu that allows the user to choose these stack operations and includes error handling for invalid inputs or overflow/underflow of the stack.