View All C Programs

 Previews Example  View All C Programs Next Example 

Program for switch case to perform add , multiply sub , div operation in C

#include <stdio.h>
#include <conio.h>
main()
{
    int choice, a, b;
    int sum, div, mul, sub;
    char c= 'y';

    while(c=='y')
    {
         printf("\nAddition  -> 1\nSubtraction  -> 2 \nMultiplication  -> 3 \nDivision  -> 4\n");
         printf("Enter your choice of operation to perform -: \n");
         scanf("%d",& choice);
         printf("\nEnter two number :- \n");
         scanf("%d%d",&a,&b);
         switch(choice)
         {

              case 1: sum = a + b;
              printf("\n Sum = %d", sum);
              break;

              case 2: sub = a - b;
              printf("\n Difference = %d", sub);
              break;

              case 3: mul = a * b;
              printf("\n Multiplication = %d", mul);
              break;

              case 4: div = a - b;
              printf("\n Division = %d", div);
              break;

              default : printf("\aWRONG CHOICE");
        }
        printf("\nDo you want to continue [y / n]");
        c=getch();
    }
    getch();
}
    
Result
Addition -> 1
Subtraction -> 2
Multiplication -> 3
Division -> 4
Enter your choice of operation to perform -:
1

Enter two number :-
10
10
Sum = 20


Do you want to continue [y / n]
Addition -> 1
Subtraction -> 2
Multiplication -> 3
Division -> 4
Enter your choice of operation to perform -:
3

Enter two number :-
5
10
Sum = 50


Do you want to continue [y / n]...