program-
#include< stdio.h>
#include< conio.h>
#define max 50
int stack[max],top=-1;
void create()
{
char ch;
do
{
top++;
printf("Enter Number\n");
scanf("%d",&stack[top]);
printf("Continue(y/n)\n");
ch=getch();
}while(ch=='y');
}
void traverse()
{
int i;
printf("Stack is :\n");
for(i=top;i>=0;i--){
printf("%d ",stack[i]);
}
}
void count()
{
int n,i,count=0;
printf("Enter number to count in stack\n");
scanf("%d",&n);
for(i=top;i>=0;i--)
{
if(stack[i]==n)
count++;
}
printf("Occurrence of %d is %d",n,count);
}
void main()
{
clrscr();
create();
traverse();
count();
getch();
}
Enter Number
3
Enter Number
4
Continue(y/n)?
Enter Number
7
Continue(y/n)?
Enter Number
3
Continue(y/n)?
Enter Number
1
Continue(y/n)?
Enter Number
3
Continue(y/n)?
Enter Number
1
Continue(y/n)?
Stack is :
1 3 1 3 7 4 3
Enter number to count in stack
3
Occurrence of 3 is 3