0% found this document useful (0 votes)
3 views

Assignment 6

Uploaded by

nehal.arora
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Assignment 6

Uploaded by

nehal.arora
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

#include<stdio.

h>

#include<stdlib.h>

#define MAX 5

struct stack

int stk[MAX];

int top;

}st;

void display();

int main()

int ch,num;

st.top=-1;

do{

printf("\n1.Push\n2.Pop\n");

printf("Enter your choice: ");

scanf("%d",&ch);

switch(ch)

case 1:

printf("Push\n");

if(st.top==MAX-1)

printf("Stack is Full!!\n");

else

printf("Enter the element to be pushed: \n");

scanf("%d",&num);

st.top++;
st.stk[st.top]=num;

}display();

break;

case 2:

printf("Pop\n");

if(st.top==-1)

printf("Stack is Empty!!\n");

else

num=st.stk[st.top];

st.top--;

printf("Popped element is: %d\n",num);

}display();

break;

}while(ch!=3);

void display()

int i;

if(st.top==-1)

printf("Stack is Empty\n");

else

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

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

printf("%d\t\n",st.stk[i]);

OUTPUT:

1.Push

2.Pop

Enter your choice: 1

Push

Enter the element to be pushed:

The stack is:

1.Push

2.Pop

Enter your choice: 1

Push

Enter the element to be pushed:

The stack is:

1.Push

2.Pop

Enter your choice: 1

Push
Enter the element to be pushed:

The stack is:

1.Push

2.Pop

Enter your choice: 1

Push

Enter the element to be pushed:

The stack is:

1.Push

2.Pop

Enter your choice: 1

Push

Enter the element to be pushed:

The stack is:

1
1.Push

2.Pop

Enter your choice: 2

Pop

Popped element is: 5

The stack is:

1.Push

2.Pop

Enter your choice: 2

Pop

Popped element is: 3

The stack is:

1.Push

2.Pop

Enter your choice: 3

PS D:\S.Y\C programming>

You might also like