Update cv3/program.c
This commit is contained in:
parent
53fedccf2e
commit
c5605e5b2c
@ -1,7 +1,7 @@
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
////@@@@
|
||||
#define STACK_SIZE 500
|
||||
|
||||
struct Stack
|
||||
@ -17,13 +17,13 @@ int count_stack(struct Stack* stack);
|
||||
|
||||
void push_stack(struct Stack* stack, float value)
|
||||
{
|
||||
assert(stack->size < STACK_SIZE);
|
||||
assert(stack->size < STACK_SIZE); // Program spadne, ak zapisuje mimo
|
||||
stack->values[stack->size] = value;
|
||||
stack->size += 1;
|
||||
}
|
||||
float pop_stack(struct Stack* stack)
|
||||
{
|
||||
assert(stack->size > 0);
|
||||
assert(stack->size > 0); // Program spadne, ak číta mimo
|
||||
float value = stack->values[stack->size-1];
|
||||
stack->size -= 1;
|
||||
return value;
|
||||
@ -37,8 +37,9 @@ void print_stack(struct Stack* stack)
|
||||
{
|
||||
for (int i=0; i<stack->size; i++)
|
||||
{
|
||||
printf("%f/", stack->values[i]);
|
||||
printf("%.2f ", stack->values[i]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
|
||||
@ -54,9 +55,10 @@ int main()
|
||||
do
|
||||
{
|
||||
char* p=fgets(buf, 299, stdin);
|
||||
|
||||
//printf("{%s}",buf);
|
||||
if(!p)
|
||||
{
|
||||
{
|
||||
//printf("==");
|
||||
break;
|
||||
}
|
||||
else
|
||||
@ -73,13 +75,15 @@ int main()
|
||||
case '-': rez=op1-op2; break;
|
||||
case '/': rez=op1/op2; break;
|
||||
case '*': rez=op1*op2; break;
|
||||
}
|
||||
push_stack(&mystack, rez);
|
||||
printf(" %.2f\n", rez);
|
||||
|
||||
} //p
|
||||
}
|
||||
else
|
||||
push_stack(&mystack, atof(buf));
|
||||
{
|
||||
rez=atof(buf);
|
||||
}
|
||||
push_stack(&mystack, rez);
|
||||
//printf(" %.2f\n", rez);
|
||||
print_stack(&mystack);
|
||||
}
|
||||
|
||||
}while(1);
|
||||
|
Loading…
Reference in New Issue
Block a user