-
Notifications
You must be signed in to change notification settings - Fork 0
/
evapofx.c
36 lines (36 loc) · 847 Bytes
/
evapofx.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <stdio.h>
#include <conio.h>
push(float s[],int *top,float elem)
{
s[++(*top)]=elem;
}
float pop(float s[],int *top)
{
return(s[(*top)--]);
}
void main()
{
float s[100];int tp=-1;
char po[100],ch;
int i=0;float op1,op2;
printf("\n\nRead the Postfix Expression ? ");
scanf("%s",po);
while(ch=po[i++])
{
if(isdigit(ch)) push(s,&tp,ch-'0');
else
{
op2=pop(s,&tp);
op1=pop(s,&tp);
switch(ch)
{
case '+':push(s,&tp,op1+op2);break;
case '-':push(s,&tp,op1-op2);break;
case '*':push(s,&tp,op1*op2);break;
case '/':push(s,&tp,op1/op2);break;
}
}
}
printf("\n Given Postfix Expn: %s\n",po);
printf("\n Result after Evaluation: %f\n",s[tp]);
}