This commit is contained in:
Oleksandr Vyshniakov 2025-10-12 21:57:19 +02:00
parent 780529c399
commit e7a9c71f3d
2 changed files with 42 additions and 7 deletions

Binary file not shown.

View File

@ -57,12 +57,47 @@ void destroy_stack (struct stack* s) {
} }
int main() { int main() {
struct stack* novystack = create_stack(STACK_SIZE); struct stack* s = create_stack(STACK_SIZE);
push_stack(novystack, 3.14); char input[101];
push_stack(novystack, 2.71); while (scanf("%s", input)==1) {
float x = pop_stack(novystack); char *end;
printf("Popped: %2.f\n", x); float value = strtof(input, &end);
print_stack(novystack); if (*end == '\0') {
destroy_stack(novystack); push_stack(s, value);
print_stack(s);
} else if (strcmp(input, "+")==0 || strcmp(input, "-")==0 || strcmp(input, "*")==0 || strcmp(input, "/")==0) {
if (s->size < 2) {
printf("no input\n");
destroy_stack(s);
return 0;
}
float b = pop_stack(s);
float a = pop_stack(s);
float result = 0;
if (strcmp(input, "+")==0) {
result = a+b;
}
if (strcmp(input, "-")==0) {
result = a - b;
}
if (strcmp(input, "*")==0) {
result = a * b;
}
if (strcmp(input, "/")==0) {
result = a/b;
}
push_stack(s);
print_stack(s);
}
else {
printf("no input");
destroy_stack(s);
return 0;
}
}
destroy_stack(s);
return 0; return 0;
} }