Skip to content

Instantly share code, notes, and snippets.

Created February 3, 2013 12:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/4701673 to your computer and use it in GitHub Desktop.
Save anonymous/4701673 to your computer and use it in GitHub Desktop.
#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