Question: Program 4.2 is prepared for eveluating a given postfix expression. When you run this program postfix expression must be given as input string and program

 Program 4.2 is prepared for eveluating a given postfix expression. When

you run this program postfix expression must be given as input string

and program will generate an output as numeric real number that is

Program 4.2 is prepared for eveluating a given postfix expression. When you run this program postfix expression must be given as input string and program will generate an output as numeric real number that is called as evaluated value. Hint: postfix expression consist of one digit numeric operands and operators and only. Example data for the program could be as follows a) If you give input string as 9142/+- 23 * / Program will generate evaluated output as 1.0 b) If you give input string as 392 3 $ -* 6+ and evaluated value as 9.00 Program4.2 Postfix Evaluated value * #include #include #include #define MAXCOLS 80 struct stack{ int top; double items[MAXCOLS); double eval(char[]); double pop(struct stack"); void push(struct stack double); int empty(struct stack *); int isdigit(char); double oper(int,double double); void main(void) { char expr|MAXCOLS; int pos=0; while((expr[pos++] = getchar()) != ' '); expr|--pos] = '0'; printf("%s%s", " the original postfix expression is ",expr); getchar(); printf(" %f", eval(expr)); getchar(); } double pop(struct stack "ps) { double x; if (ps->top=-1) { printf("%s","stack underflow"); exit(1); } else{ x=ps->items [ps->top); ps->top=ps->top - 1; } return x; } void push(struct stack *ps, double x) { if (ps->top = MAXCOLS-1) { printf("%s","stack overflow "); exit(1); } else{ ps->top=ps->top + 1; ps->items [ps->topl=x; } } double eval(char expril) { inte, pos; double opnd 1, opnd2, value ; struct stack s; s.top=-1; for(pos=0; (c=exprlposition])!="0'; pos++) if (isdigit(e)) push(&s,(double)(e-'0')); else { opnd2=pop(&s); opndl-pop(&s); value=oper(c ,opnd1 ,opnd2); push(&s,value); return(pop(&s)); } int isdigit(char symb) { return (symb >= '0' && symb

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!