//You can do it as follows in C programming:
#include <stdio.h>
#include <ctype.h>
#include <conio.h>
int STACK[100];
int top = 0;
int flag = 0;
void push(int item)
{
int MaxStacks = 100;
if (top >= MaxStacks)
{
printf("Overflow\n");
return;
}
else if (flag == 1)
{
int newelem;
newelem = STACK[top];
STACK[top] = item + 10 * newelem;
}
else if (flag == 0)
{
top = top + 1;
STACK[top] = item;
flag = 1;
}
}
int pop()
{
int item;
if (top <= 0)
{
printf("Underflow\n");
}
else
{
item = STACK[top];
top = top - 1;
}
return 0;
}
void evaluate(char elem[])
{
int i;
int A, B;
char ch;
int result;
A = 0;
B = 0;
for (i = 0; elem[i] != ')'; i++)
{
ch = elem[i];
if (isdigit(ch))
{
push(ch - '0');
}
else if (ch == '\n')
{
flag = 0;
}
else if (ch == '+' || ch == '*' || ch == '-' || ch == '/')
{
flag = 0;
A = STACK[top];
pop();
B = STACK[top];
pop();
switch (ch)
{
case '+':
result = B + A;
break;
case '-':
result = B - A;
break;
case '*':
result = B * A;
break;
case '/':
result = B / A;
break;
}
push(result);
}
}
printf("Result of Post fix expression is %d\n", STACK[top]);
}
int main()
{
int i;
char elem[100];
// clrscr();
printf("Enter the elements of the post fix expression\n and enter right
parenthesis ')' at the end of the expression.\n");
for (i = 0; i <= 100; i++)
{
scanf("%c", &elem[i]);
if (elem[i] == ')')
{
break;
}
}
evaluate(elem);
getch();
return 0;
}