cv3.2
This commit is contained in:
parent
f3b4bdb351
commit
161b9f4bd9
@ -26,10 +26,10 @@ void print_stack(struct stack *stack){
|
||||
int i;
|
||||
int len = stack->size - 1;
|
||||
for(i = 0; i < len; i++){
|
||||
printf("%0.2g ", stack->values[i]);
|
||||
printf("%0.2f ", stack->values[i]);
|
||||
}
|
||||
if(stack->size != 0){
|
||||
printf("%0.2g ", stack->values[i]);
|
||||
printf("%0.2f ", stack->values[i]);
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
@ -40,6 +40,7 @@ int main() {
|
||||
struct stack mystack;
|
||||
memset(&mystack, 0, sizeof(struct stack));
|
||||
int i = 0;
|
||||
float z;
|
||||
for(i = 0; i < 10000; i++){
|
||||
char line[10];
|
||||
char *x = fgets(line, 10, stdin);
|
||||
@ -53,13 +54,17 @@ int main() {
|
||||
r = pop(&mystack) + pop(&mystack);
|
||||
}
|
||||
else if(line[0] == '-'){
|
||||
r = pop(&mystack) - pop(&mystack);
|
||||
z = pop(&mystack);
|
||||
r = pop(&mystack) - z;
|
||||
}
|
||||
else if(line[0] == '*'){
|
||||
r = pop(&mystack) * pop(&mystack);
|
||||
}
|
||||
else if(line[0] == '/'){
|
||||
r = pop(&mystack) / pop(&mystack);
|
||||
z = pop(&mystack);
|
||||
if(z != 0.0){
|
||||
r = pop(&mystack) / z;
|
||||
}
|
||||
}
|
||||
|
||||
else {
|
||||
|
Loading…
Reference in New Issue
Block a user