This commit is contained in:
Maryna Kravtsova 2020-10-11 14:43:09 +02:00
parent f3b4bdb351
commit 161b9f4bd9

View File

@ -26,10 +26,10 @@ void print_stack(struct stack *stack){
int i; int i;
int len = stack->size - 1; int len = stack->size - 1;
for(i = 0; i < len; i++){ for(i = 0; i < len; i++){
printf("%0.2g ", stack->values[i]); printf("%0.2f ", stack->values[i]);
} }
if(stack->size != 0){ if(stack->size != 0){
printf("%0.2g ", stack->values[i]); printf("%0.2f ", stack->values[i]);
} }
printf("\n"); printf("\n");
@ -40,6 +40,7 @@ int main() {
struct stack mystack; struct stack mystack;
memset(&mystack, 0, sizeof(struct stack)); memset(&mystack, 0, sizeof(struct stack));
int i = 0; int i = 0;
float z;
for(i = 0; i < 10000; i++){ for(i = 0; i < 10000; i++){
char line[10]; char line[10];
char *x = fgets(line, 10, stdin); char *x = fgets(line, 10, stdin);
@ -53,13 +54,17 @@ int main() {
r = pop(&mystack) + pop(&mystack); r = pop(&mystack) + pop(&mystack);
} }
else if(line[0] == '-'){ else if(line[0] == '-'){
r = pop(&mystack) - pop(&mystack); z = pop(&mystack);
r = pop(&mystack) - z;
} }
else if(line[0] == '*'){ else if(line[0] == '*'){
r = pop(&mystack) * pop(&mystack); r = pop(&mystack) * pop(&mystack);
} }
else if(line[0] == '/'){ else if(line[0] == '/'){
r = pop(&mystack) / pop(&mystack); z = pop(&mystack);
if(z != 0.0){
r = pop(&mystack) / z;
}
} }
else { else {