From 85f66425f9c8ec31977f6a2df99d17cd383d4523 Mon Sep 17 00:00:00 2001 From: Yevhen Kozirovskyi Date: Thu, 17 Oct 2024 17:07:03 +0000 Subject: [PATCH] =?UTF-8?q?=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2=D0=B8=D1=82?= =?UTF-8?q?=D1=8C=20cv3/program.c?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cv3/program.c | 54 +++++++++++++-------------------------------------- 1 file changed, 13 insertions(+), 41 deletions(-) diff --git a/cv3/program.c b/cv3/program.c index c386dbd..77eb87b 100644 --- a/cv3/program.c +++ b/cv3/program.c @@ -51,7 +51,7 @@ int main() { if (c == '\n' && *bufer != '\n' && *bufer != ' ') { push(&stek, chislo); - } else if (c == '+') { + } else if (c == '+' || c == '-' || c == '*' || c == '/') { if (isEmpty(&stek)) { printf("no input\n"); exit(1); @@ -62,47 +62,19 @@ int main() { exit(1); } double a = pop(&stek); - push(&stek, a + b); - } else if (c == '-') { - if (isEmpty(&stek)) { - printf("no input\n"); - exit(1); + if (c == '+') { + push(&stek, a + b); + } else if (c == '-') { + push(&stek, a - b); + } else if (c == '*') { + push(&stek, a * b); + } else if (c == '/') { + if (b == 0) { + printf("division by zero\n"); + return 0; + } + push(&stek, a / b); } - double b = pop(&stek); - if (isEmpty(&stek)) { - printf("no input\n"); - exit(1); - } - double a = pop(&stek); - push(&stek, a - b); - } else if (c == '*') { - if (isEmpty(&stek)) { - printf("no input\n"); - exit(1); - } - double b = pop(&stek); - if (isEmpty(&stek)) { - printf("no input\n"); - exit(1); - } - double a = pop(&stek); - push(&stek, a * b); - } else if (c == '/') { - if (isEmpty(&stek)) { - printf("no input\n"); - exit(1); - } - double b = pop(&stek); - if (isEmpty(&stek)) { - printf("no input\n"); - exit(1); - } - double a = pop(&stek); - if (b == 0) { - printf("division by zero\n"); - return 0; - } - push(&stek, a / b); } else if (isalpha(c)) { printf("bad input\n"); return 0;