#include #include /* atof() */ #define MAXLEN 100 /* function prototypes */ int getop(char []); void push(double); double pop(void); /* reverse Polish calculator */ main() { int type; double op2; char s[MAXLEN]; while ((type = getop(s)) != EOF) { switch (type) { case '0': push(atof(s)); break; case '+': push(pop() + pop()); break; case '*': push(pop() * pop()); break; case '-': op2 = pop(); push(pop() - op2); break; case '/': op2 = pop(); if (op2 != 0.0) push(pop() / op2); else printf("ERROR: Division by zero!\n"); break; case '\n': printf("\t%f\n", pop()); break; default: printf("ERROR: Unknown input!\n"); break; } } }