Update calc.c

code refactored