diff options
-rw-r--r-- | ex4-3.c | 12 |
1 files changed, 12 insertions, 0 deletions
@@ -10,6 +10,11 @@ int getop(char[]); void push(double); double pop(void); +// Naïve implementation of remainder operation +double frem(double f1, double f2) { + return f1 - (f2 * (int)(f1 / f2)); +} + /** * Reverse polish notation calculator */ @@ -39,6 +44,13 @@ int main(void) { else printf("error: zero division attempted!\n"); break; + case '%': + op2 = pop(); + if (op2 != 0.0) + push(frem(pop(), op2)); + else + printf("error: zero division attempted!\n"); + break; case '\n': printf("\t%.8g\n", pop()); break; |