Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<string.h>
- #include<math.h>
- int stack[50],top=-1;
- void push(int v);
- int pop();
- int cal(char v);
- int main(){
- int i=0,t;
- char s[128];
- printf("Enter: ");
- gets(s); fflush(stdin);
- while(i<strlen(s)){
- if(s[i]<='9'&&s[i]>='0'){
- push(s[i]-'0');
- }
- else{
- t=cal(s[i]);
- }
- i++;
- }
- i=0;
- printf("=%d",t);
- return 0;
- }
- void push(int v){
- if(top>50){
- printf("FULL\n");
- }
- top = top + 1 ;
- stack[top]= v;
- }
- int pop(){
- return stack[top--];
- }
- int cal(char v){
- int x,y,temp,k;
- y = pop();
- //printf("%d ",y);
- x = pop();
- //
- //printf("%d ",x);
- if(v=='+'){
- temp = x+y;
- }else if(v=='-'){
- temp = x-y;
- }else if(v=='*'){
- temp = x*y;
- }else if(v=='/'){
- temp = x/y;
- }else if(v=='%'){
- temp = x%y;
- }else if(v=='^'){
- temp = pow(x,y);
- }else{
- printf("empty\n");
- }
- push(temp);
- return temp;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement