// STACK
// Program 1 : To implement stack using array

#include <stdio.h>
#include <conio.h>

#define MAX 20

 int stack[MAX];
 int top = -1; // means stack is empty

 int push(int );
 int pop ();
void show();

main()
{
	int x, opn;
	
	do
	{
		printf("\n\n\t <1>PUSH    <2>POP    <3>SHOW    <4>EXIT");
		printf("\n\t Enter your option : ");
		scanf("%d",&opn);
		
		switch(opn)
		{
			case 1: printf("\t Enter number to push : ");
				scanf("%d", &x);
				if( push(x))
					printf("\n\t ERROR : OVERFLOW !!!");
				printf("\t Press any key to continue ...");
				getch();
				break;
			
			case 2: if( top == -1)
					printf("\n\t ERROR : UNDERFLOW !!!");
				else
					printf("\t poped number is : %d ", pop());
				printf("\t Press any key to continue ...");
				getch();
				break;
			
			case 3: if( top == -1)
					printf("\n\t STACK IS EMPTY");
				else
					show();
				printf("\t Press any key to continue ...");
				getch();
				break;
		}
	}while( opn != 4);
}
// end of main

int push(int x)
{
	if( top == MAX-1)
		return -1;
	top ++;
	stack[ top] = x;
	return 0;
}

int pop ()
{
	if( top == -1)
		return -1;
	top --;
	return stack[ top + 1];
}

void show (  )
{
	int i;
	if( top == -1)
		return ;
	printf("\n\t STACK = [ ");
	for( i=0; i<=top; i++)
		printf(" %d ", stack[i]);
	printf("]");
}



Output