//program to evaluate postfix expression
#include<stdio.h>
#include<ctype.h>
int stk[20],top=-1;
void push(int a);
int pop();
void main()
{
char exp[20];
int i,v,n1,n2;
printf("\n enter postfix exp");
gets(exp);
for(i=0;exp[i]!='\0';i++)
{
if(isdigit(exp[i]))
{
push(exp[i]-'0');
}
else if(isalpha(exp[i]))
{
printf("\n alphabets not allowed");
}
else
{
n2=pop();
n1=pop();
switch(exp[i])
{
case '+':push(n1+n2);
break;
case '-':push(n1-n2);
break;
case '/':push(n1/n2);
break;
case '*':push(n1*n2);
break;
default: printf("\n enter valid operator(+, -, *, /)");
}
}
}
printf("result value is: %d",stk[top]);
}
void push(int a)
{
stk[++top]=a;
}
int pop()
{
if(top==-1)
return -1;
else
return stk[top--];
}