Articles & News Stories

Evaluation of Postfix

Description
Description:
Published
of 2
All materials on our website are shared by users. If you have any questions about copyright issues, please report us to resolve them. We are always happy to assist you.
Share
Transcript
  #include<stdio.h> #include<conio.h> #include<string.h> #include<ctype.h> #include<stdlib.h> #define MAX 20 float st[MAX]; int top=-1; void push(float st[],char); float pop(float st[ float evaluatePostfixExp(char exp[ int main() { float val; char exp[100]; printf( \n Enter the postfix Expression ); gets(exp); val=evaluatePostfixExp(exp); printf( \n Value of the postfix expression = %.2f ,val); getch(); return 0; } float evaluatePostfixExp(char exp[]) { int i=0; float op1,op2; while(exp[i]!='\0'); { if(isdigit(exp[i])) push(st,(float)(exp[i]-'0')); else { op2=pop(st); op1=pop(st); switch(exp[i]) { case '+': value=op1+op2; break; case '-': value=op1-op2; break;   case '/': value=op1-op2; break; case '%': value=op1%op2; break; } push(st,value); } i++ } return(pop(st)); } void push(float st[],float val) { if(top==MAX-1) printf( OVERFLOW\n ); else { top++; st[top]=val; } } float pop(float st[]) { int val; if(top==-1) printf( UNDERFLOW\n ); else { val=st[top]; top--; } return val; } Output: Enter the postfix Expression :9 3 4 *8 +4 / - Value of the postfix expression =4.00
Search
Related Search
We Need Your Support
Thank you for visiting our website and your interest in our free products and services. We are nonprofit website to share and download documents. To the running of this website, we need your help to support us.

Thanks to everyone for your continued support.

No, Thanks
SAVE OUR EARTH

We need your sign to support Project to invent "SMART AND CONTROLLABLE REFLECTIVE BALLOONS" to cover the Sun and Save Our Earth.

More details...

Sign Now!

We are very appreciated for your Prompt Action!

x