How To Make Simple Calculator Program in C

 

Calculator Program in C Algorithm

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.

C

Output:

calculator program in c
simple calculator program in c

In the above 1 output Addition operation is done because of user input 1 for addition. In second output multiplication is done because of input 3 for operation.

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.

C

Output:

calculator in c

In the above program, the compiler is asking the user to enter the arithmetic operators such as +,-,*,/ and also ask to input two numbers so the operations can be done using two numbers.

3. Simple Calculator Program in C Using if-else Statement

In this program, we will use else if statement instead of switch case statement.

C

Output:

calculator program in c using else if
calculator in c using else if

4. Calculator Program in C Using Function

In this program, we have declared user-defined functions.

C


No comments