diff options
author | Martin Ashby <martin@ashbysoft.com> | 2022-11-21 20:39:02 +0000 |
---|---|---|
committer | Martin Ashby <martin@ashbysoft.com> | 2022-11-21 20:39:02 +0000 |
commit | 50534766e09667a9c23c1f167dca92f5d4fd0f27 (patch) | |
tree | e9b0bcfb282d67ec9f89433467cd988dde9976f4 | |
parent | 5a72e2df2d68116241cf053b78a0f78135b02e7b (diff) | |
download | learn-c-50534766e09667a9c23c1f167dca92f5d4fd0f27.tar.gz learn-c-50534766e09667a9c23c1f167dca92f5d4fd0f27.tar.bz2 learn-c-50534766e09667a9c23c1f167dca92f5d4fd0f27.tar.xz learn-c-50534766e09667a9c23c1f167dca92f5d4fd0f27.zip |
Actually implement ex4-3
-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; |