Created
February 3, 2013 12:55
-
-
Save anonymous/4701673 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <ctype.h> | |
#include <stdlib.h> | |
#define _CRT_SECURE_NO_DEPRECATE | |
int stack[100]; | |
int top; | |
void push(int x){ | |
top++; | |
stack[top] = x; | |
} | |
int pop(){ | |
int temp = stack[top]; | |
top--; | |
return(temp); | |
} | |
int main() | |
{ | |
char input[13]; | |
int integer, a, b, result; | |
while(1){ | |
scanf("%s", input); | |
if (isdigit(input[0])) { | |
integer = atoi(input); | |
push(integer); | |
} | |
if (input[0] == '+'){ | |
b = pop(); | |
a = pop(); | |
push (a+b); | |
} | |
else{ | |
if (input[0] == '-'){ | |
b = pop(); | |
a = pop(); | |
push (a-b); | |
} | |
else{ | |
if (input[0] == '*'){ | |
b = pop(); | |
a = pop(); | |
push (a*b); | |
} | |
} | |
} | |
if (input[0] == 'p'){ | |
result = pop(); | |
printf("%d\n", result); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment