0% found this document useful (0 votes)
4 views3 pages

Stack Operations in C Programming

Uploaded by

yash.sahay787
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views3 pages

Stack Operations in C Programming

Uploaded by

yash.sahay787
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

//Roll no.

78 Batch B3

#include <stdio.h>

#include <stdlib.h>

#define MAX 100

int stack[MAX];

int top = -1;

int value, choice, i;

void push() {

if (top == MAX - 1) {

printf("Stack Overflow! Cannot push more elements.\n");

} else {
else {
printf("Enter the value to push: ");

scanf("%d", &value);

top++;

stack[top] = value;

printf("%d pushed to stack.\n", value);

void pop() {

if (top == -1) {

printf("Stack Underflow! No elements to pop.\n");

} else {
else {
printf("%d popped from stack.\n", stack[top]);

top--;

void display() {

if (top == -1) {

printf("Stack is empty.\n");

} else {

printf("Stack elements are:\n");

for (i = top; i >= 0; i--) {

printf("%d\n", stack[i]);

int main() {

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;
break;
case 2: pop(); break;
break;
case 3: display(); break;
break;
case 4:

printf("Exiting program.\n");

exit(0);

default:

printf("Invalid choice! Please try again.\n");

return 0;

You might also like