Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cctype>
- using namespace std;
- int main()
- {
- int wynik,licz1=0,licz2=0;
- int ile,n=0;
- cout <<"ile znakow?"<<endl;
- cin >>ile;
- char tab[ile];
- for(int i=0;i<ile;i++)
- cin >>tab[i];
- int stos[30]={0};
- for (int i=0;i<ile;i++)
- {
- if (isdigit(tab[i]))
- stos[n++]=tab[i]-'0';
- else
- {
- licz1=stos[--n];
- licz2=stos[--n];
- switch (tab[i])
- {
- case '*':
- stos[n++]=licz2*licz1;
- break;
- case '+':
- stos[n++]=licz2+licz1;
- break;
- case '-':
- stos[n++]=licz2-licz1;
- break;
- case '/':
- stos[n++]=licz2/licz1;
- break;
- }
- }
- }
- wynik=stos[0];
- cout <<wynik<<endl;
- return 0;
- }
- /*
- 42 *
- 43 +
- 45 -
- 47 /
- 48 0
- 57 9
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement