0% found this document useful (0 votes)
13 views3 pages

p13 (Postfix Expression Evaluation)

Uploaded by

abaiju696
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views3 pages

p13 (Postfix Expression Evaluation)

Uploaded by

abaiju696
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

/*postfix expression evaluation*/

#include<stdio.h>

#include<string.h>

#include<math.h>

#include<ctype.h>

#define MAX 20

int s[MAX],top=0;

void push(int ch);

int pop();

void main()

char postfix[MAX], ch;

int i,op1, op2, res;

printf("\n\t\tProgram to Evaluate Postfix Expression.");

printf("\n Enter the postfix expression: \n");

scanf("%s",postfix);

for (i=0;i<strlen(postfix); i++)

ch=postfix[i];

if(isdigit(ch))/* Check whether digit */

push(ch-'0');

else

op2=pop();

op1=pop();

switch(ch)

case '+':

res = op1 + op2;

break;

case '-':
res=op1-op2;

break;

case '*':

res=op1*op2;

break;

case '/':

res = op1 / op2;

break;

case '^':

res = pow(op1, op2);

break;

default:

printf(" Invalid Character \n");

push(res);

printf("Result of above expression is: %d\n", pop());

void push(int element)

++top;

s[top]=element;

int pop()

int elements;

elements=s[top];

--top;

return(elements);

}
OUTPUT

You might also like