Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <ctype.h>
- #include <math.h>
- int stack[100];
- int top=-1;
- void push(int element)
- {
- stack[++top]=element;
- }
- int pop()
- {
- return(stack[top--]);
- }
- int main()
- {
- char postfix[100],ch,j;
- int i=0,a,b;
- printf("Expression:\n");
- scanf("%s",postfix);
- while( (ch=postfix[i++]) != '\0')
- {
- if(isdigit(ch))
- push(ch-'0');
- else
- {
- b=pop();
- a=pop();
- if(ch=='+')
- push(a+b);
- if(ch=='-')
- push(a-b);
- if(ch=='*')
- push(a*b);
- if(ch=='/')
- push(a/b);
- if(ch=='^')
- push(pow((float)a,b));
- }
- }
- printf("\nPostfix: %s\n",postfix);
- printf("\nEvaluation: %d\n",stack[top]);
- getchar();
- getchar();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement