forked from rohangoyal755/DataStructure
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path6.2.cpp
More file actions
41 lines (40 loc) · 778 Bytes
/
6.2.cpp
File metadata and controls
41 lines (40 loc) · 778 Bytes
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
#include <iostream>
#include <string.h>
using namespace std;
int main()
{
cout<<"Enter the postfix expression"<<endl;
char s[100];
int x,y,z;
cin.get(s,100);
int l=strlen(s);
int a[100];
int t=-1;
for(int i=0;i<l;i++)
{
if(isdigit(s[i]))
{
t++;
a[t]=s[i]-'0';
}
else
{
x=a[t];
t--;
y=a[t];
t--;
if(s[i]=='*')
z=(y)*(x);
else if(s[i]=='+')
z=(y)+(x);
else if(s[i]=='-')
z=(y)-(x);\
else if(s[i]=='/')
z=(y)/(x);
t++;
a[t]=z;
}
}
cout<<"Answer is= "<<a[t]<<endl;
return 0;
}