summaryrefslogtreecommitdiffstats
path: root/4/10.c
diff options
context:
space:
mode:
authorSadeep Madurange <smadurange@users.noreply.github.com>2021-12-18 14:20:34 +0800
committerSadeep Madurange <smadurange@users.noreply.github.com>2021-12-18 14:20:34 +0800
commitd3687f51f444636b7974a68c159b2fa4d42162d0 (patch)
tree4ee152953da7cda05efe5e545547978ab03eef97 /4/10.c
parent17400db194b140fba5c709c5e01ec57fa5c5197a (diff)
downloadk&r-exercises-d3687f51f444636b7974a68c159b2fa4d42162d0.tar.gz
4.10
Diffstat (limited to '4/10.c')
-rw-r--r--4/10.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/4/10.c b/4/10.c
index c8df3ee..25b3e1a 100644
--- a/4/10.c
+++ b/4/10.c
@@ -77,6 +77,30 @@ int main(int argc, char *argv[]) {
push(var[INDEX(s[0])]);
break;
case FUN:
+ if (strcmp("sin", s) == 0)
+ push(sin(pop()));
+ else if (strcmp("cos", s) == 0)
+ push(cos(pop()));
+ else if (strcmp("tan", s) == 0)
+ push(tan(pop()));
+ else if (strcmp("exp", s) == 0)
+ push(exp(pop()));
+ else if (strcmp("pow", s) == 0)
+ push(pow(pop(), pop()));
+ else if (strcmp("cls", s) == 0)
+ clear();
+ else if (strcmp("top", s) == 0) {
+ lout = peek();
+ printf("\t%.8g\n", lout);
+ } else if (strcmp("swp", s) == 0) {
+ op2 = pop();
+ op1 = pop();
+ push(op2);
+ push(op1);
+ } else if (strcmp("dup", s) == 0)
+ push(peek());
+ else
+ printf("error: unknown function %s\n", s);
break;
case '\n':
lout = pop();