-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathevalPost.c
More file actions
67 lines (62 loc) · 1.22 KB
/
evalPost.c
File metadata and controls
67 lines (62 loc) · 1.22 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
float s[100];
int top=-1;
void push(float item)
{
s[++top]=item;
}
float pop()
{
return s[top--];
}
int is_oper(char a)
{
if (a=='+'||a=='-'||a=='*'||a=='/'||a=='^')
return 1;
else
return 0;
}
void main()
{
char postfix[100],i=0;
gets(postfix);
while(postfix[i]!='\0')
{
float op1, op2;
char item = postfix[i];
if (is_oper(item)==0)
{
float m;
printf("Enter Value for %c : ",item);
scanf("%f",&m);
push(m);
}
else
{
op2 = pop();
op1 = pop();
switch(item)
{
case '+':
push(op1+op2);
break;
case '-':
push(op1-op2);
break;
case '/':
push(op1/op2);
break;
case '*':
push(op1*op2);
break;
case '^':
push(pow(op1,op2));
break;
}
}
i++;
}
printf("result : %f",s[0]);
}