0% found this document useful (0 votes)
5 views5 pages

Experiment 1

The document contains a C program that implements stack operations using an array, allowing users to push, pop, and display elements in the stack. It includes a menu-driven interface for user interaction and handles overflow and underflow conditions. The program successfully executes a series of stack operations based on user input until the exit option is selected.

Uploaded by

Sharayu Kulkarni
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)
5 views5 pages

Experiment 1

The document contains a C program that implements stack operations using an array, allowing users to push, pop, and display elements in the stack. It includes a menu-driven interface for user interaction and handles overflow and underflow conditions. The program successfully executes a series of stack operations based on user input until the exit option is selected.

Uploaded by

Sharayu Kulkarni
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
You are on page 1/ 5

Roll no: 18

Name: Sharayu Sandeep Kulkarni

#include <stdio.h>

int stack [100],choice,n,top,x,i;

void push (void);

void pop (void);

void display (void);

int main()

top=-1;

printf("\n Enter the size of the STACK [MAX=100]:");

scanf("%d",&n);

printf("\n\t STACK OPERATIONS USING ARRAY");

printf("\n\t-----------------------------");

printf("\n\t 1.PUSH \n\t 2.POP \n\t 3.DISPLAY \n\t 4.EXIT");

do

printf("\n Enter the choice:");

scanf("%d",&choice);

switch(choice)

case 1:

push();

break;

case 2:

pop();

break;
}

case 3:

display();

break;

case 4:

printf("\n\t EXIT POINT");

break;

default:

printf("\n\t Please Enter a valid choice (1/2/3/4)");

while(choice!=4);

return 0;

void push()

if (top>=n-1)

printf("\n\t STACK is over flow");

else

printf("Enter a value to be pushed:");

scanf("%d",&x);

top++;
stack [top]=x;

void pop()

if (top<=-1)

printf("\n\t Stack is under flow");

else

printf("\n\t The popped element is %d",stack[top]);

top--;

void display()

if(top>0)

printf("\n The element in STACK\n");

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

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

printf("\n Press Next Choice");

else

printf("\n The stack is empty");

Output:
Enter the size of the STACK [MAX=100]:4

STACK OPERATIONS USING ARRAY

-------------------------------------------------

1.PUSH

2.POP

3.DISPLAY

4.EXIT

Enter the choice:1

Enter a value to be pushed:2

Enter the choice:1

Enter a value to be pushed:3

Enter the choice:1

Enter a value to be pushed:5

Enter the choice:1

Enter a value to be pushed:6

Enter the choice:3

The element in STACK

Press Next Choice

Enter the choice:1


STACK is over flow

Enter the choice:2

The popped element is 6

Enter the choice:2

The popped element is 5

Enter the choice:2

The popped element is 3

Enter the choice:2

The popped element is 2

Enter the choice:2

Stack is under flow

Enter the choice:4

EXIT POINT

=== Code Execution Successful ===

You might also like