EVALUATION OF POSTFIX EXPRESSION

#include<stdio.h>
#include<stdlib.h>

char exp[100];
int stack[50];
int top=-1;
void push(int e)
{
top = top +1;
stack[top] = e;
}
int pop()
{
int r;
r = stack[top];
top = top - 1;
return r;
}
void evaluate(char exp[])
{
int i=0,e;
for(i=0;i<strlen(exp);i++)
{
if(isdigit(exp[i])){
e = exp[i] - '0';
push(e);
}
else
{
int op1;
int op2,res;
op1 = pop();
op2 = pop();
if(exp[i]=='+')
res = op2+op1;
else if(exp[i] =='-')
res = op2-op1;
else if(exp[i]=='*')
res = op2*op1;
else
res = op2/op1;
push(res);
}
}
printf("%d",stack[top]);
}
void main()
{
printf("enter postfix expression");
scanf("%s",exp);
evaluate(exp);
}




EX :
34+
OUTPUT:
7

45*
OUTPUT
20

Comments