Addition, Subtraction, Multiplication, Division Using Switch Case In C

C Program To Implement The Switch Case That perform the Addition, Subtraction, Multiplication and Division .

Addition, Subtraction, Multiplication, Division Using Switch Case In C

ALGORITHM:-

step 1 : Start
step 2 : Define variable(Mul, Div, Add, Sub)
step 3 : Input An Character
step 4 : Perform the Airthmatic Operation According to input character(+,-,*,/)
step 5 : Display the Result
step 6 : Stop the Execution

PROGRAM CODE:-

#include
#include
int main() {
    int choice, a, b;
    int sum, div, mul, sub;
    char c = 'y';

    while (c == 'y') {
         printf("\nAdd  -> 1\nSub  -> 2\nMulti  -> 3\nDiv  -> 4\n");
         printf("Enter choice:- ");
         scanf("%d", &choice);
         printf("\nEnter two numbers:- ");
         scanf("%d%d", &a, &b);
         switch (choice) {
              case 1: sum = a + b;
              printf("Sum of a and b is:- %d", sum);
              break;

              case 2: sub = a - b;
              printf("Sub of a and b is:- %d", sub);
              break;

              case 3: mul = a * b;
              printf("Mul of a and b is:- %d", mul);
              break;

              case 4: div = a / b;
              printf("Div of a and ab is:- %d", div);
              break;

              default : printf("WRONG CHOICE");
              break;
        }
        printf("\nDo you want to continue [y / n]");
        c = getch();
    }
    getch();
}

OUTPUT:- 

Add -> 1
Sub -> 2
Mul -> 3
Div -> 4

Enter Choice: 1
Enter Two Numbers: 
10 20
Sum of a and b is:- 30

Do you want to Continue [y / n]: y

Enter Choice: 3
Enter Two Number: 
5 6
Mul of a and b is:- 30

Do you want to Continue [y / n]: n

C Program to use switch case to perform multiple arithmetic operations
Write a program to perform arithmetic operation
Sort data Element of an array using selection