#include #include #include struct stack { int aa; } *p; int top; void push(int a) { (p+top)->aa=a; top++; } pop() { int c; top--; c=(p+top)->aa; return c; } void comp(char c) { int a,b,s,i; b=pop(); a=pop(); switch (c) { case '+': a=a+b; break; case '-': a=a-b; break; case '*': a=a*b; break; case '/': a=a/b; break; case '^': // power for (s=i=1; i<=b; i++) s=s*a; a=s; break; } push(a); } void main() { int n,aa,op1; char c,fg; printf("give me the number --> "); scanf("%d",&n); p=(struct stack *)malloc(sizeof(stack)*n); top=0; aa=0; printf("give me the postfix string --> "); while ((c=getche()) != '\r') { if ((c == '+') || (c == '-') || (c == '*') || (c == '/') || (c == '^')) { if (fg == 0) { push(aa); fg=1; aa=0; } comp(c); } if (c == ' ') { if (fg == 0) { push(aa); fg=1; aa=0; } } else if ((c >= '0') && (c <= '9')) { fg=0; aa=aa*10+c-'0'; } } /* while */ op1=pop(); printf("\nthe result ---> %d\n ",op1); }