Simple Calculator Program in C – Programming Code Examples
C

Simple Calculator Program in C3 min read

This example program accepts two input numbers and performs an arithmetic operation such as addition, subtraction, division, multiplication and mod operation on them. The output is printed to the console.

Program Definition

This calculator program is built using C arithmetic operators. The user is presented with a list of choices. Once the user input his or her choice that operation is performed.




Here is the list of operations presented to the users.

  1. Addition
  2. Subtraction
  3. Multiplication
  4. Division
  5. Modulo
  6. Close

The C calculator is implemented using the switch-case mechanism of C language.

Calculator Program in C Algorithm (Pseudocode)

  • 1 Step: BEGIN.
  • 2 Step: PRINT ENTER YOUR CHOICE.
  • 3 Step: ENTER YOUR CHOICE.
  • 4 Step: ENTER TWO OPERANDS FOR OPERATION.
  • 5 Step: USER WILL ENTER +,-,*,/ .
  • 6 Step: SWITCH(OPERATOR)
  • 7 Step: DO THE OPERATION.
  • 8 Step: PRINT THE RESULT.
  • 8 Step: EXIT.

There are different methods to write a Calculator program in C we will see those program’s one by one.

1. Calculator Program in C Using Switch Case

In this program, we will ask the user to input the operation sign and the program will start doing operation and will print the output on the screen.

Output:

Code:

2. Directly doing Operation in Case Statement

This program is the same as the above program but we will do operation directly in the case statement. But, the logic behind the program is the same.

Output:

Code:

Leave a Comment