#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#define MAX 100
int stack[MAX];
int top = -1;
void push(int operand)
{
  if (top >= MAX - 1)
  {
    printf("stack Overflow\n");
    exit(1);
  }
  stack[++top] = operand;
}
int pop(){
  if (top == -1){
    printf("stack underflow\n");
    exit(1);
  }
  return stack[top--];
}
int evaluatePostfix(char* postfix){
  int i = 0;
  while (postfix[i] != '\0'){
    char current = position[i];
    if (isdigit(current)) {
      push(current - '0');
    }
    else{
      int operand2 = pop();
      int operand1 = pop();
      switch (current){
        case '+':
        push(operand1 + operand2);
        break;
        case '-':
        push(operand1 - operand2);
        break;
        case '*':
        push(operand1 * operand2);
        break;
        case '/':
        if (operand2 == 0){
          printf("division by zero error")
          exit(1);
        }
        push(operand1 / operand2);
        break;
        default:
        printf("Invalid operator: %c\n",current);
        exit();
      }
    }
    i++;
  }
  return stack[top];
}
int main(){
  char postfix[MAX];
  printf("enter the postfix expression:");
  scanf("%s", postfix);
  int result = evaluatePostfix(postfix);
  printf("result of the postfix expression: %d\n,result");
  return 0;
}
