A simple command-line calculator program written in C that supports basic arithmetic operations.
- Supports basic arithmetic operations: addition (+), subtraction (-), multiplication (*), and division (/)
- Handles operator precedence (multiplication and division are evaluated before addition and subtraction)
- Supports floating-point numbers
- Interactive input mode
- Displays results with 2 decimal places
- Compile the program:
gcc cal.c -o calculator- Run the program:
./calculator- Enter your calculation:
- Type numbers and operators in sequence
- End your calculation with '=' to see the result
- Example:
2 + 3 * 4 =will output14.00
2 + 3 =→5.0010 - 4 * 2 =→2.006 / 2 + 3 =→6.00
- The calculator follows standard operator precedence rules
- Division by zero will result in undefined behavior
- Input should be entered one number/operator at a time
- The program will continue accepting input until '=' is entered