# C Program to Perform Arithmetic Operations Using Switch

ALGORITHM:

1. Begin
2. Enter a, b values.
(ii) Print ‘- Subtraction’.
(iii) Print ‘* Multiplication’.
(iv) Print ‘/ Division’.
(v) Print ‘% Remainder’.
(vi) Print ‘E Exit’.
5. If op==’E’ then goto step 8 otherwise follow the below steps
6. Switch(op)
a. case +:
ii. c=a+b.
iii. Print ‘Sum=’c.
iv. break
b. case -:
v. Print ‘Subtraction’.
vi. c=a-b.
vii. Print ‘Difference=’c.
viii. break
c. case : ix. Print ‘Multiplication’. x. c=ab.
xi. Print ‘Product=’c.
xii. break
d. case /:
xiii. Print ‘Division’.
xiv. c=a/b.
xv. Print ‘Quotient=’c.
xvi. break
e. case %:
xvii. Print ‘Remainder’.
xviii. c=a%b.
xix. Print ‘Remainder=’c.
xx. break
f. default:
xxi. Print ‘Invalid Option’.
xxii. break
7. while(1) then goto step 3.
8. Stop.
FLOW CHART is given for the same program in Flowcharts Section.

# Program for Arithmetic Operations using SWITCH:

int main()
{
int a, b, c;
char op;
printf(“Enter a and b:”);
scanf(“%d%d”,&a,&b);
do
{
printf(“- Subtraction\n”);
printf(“* Multiplication\n”);
printf(“/ Division\n”);
printf(“%% Remainder\n”);
printf(“E Exit\n”);
getchar();
op=getchar();
if(op==’E’||op==’e’)
exit(1);
switch(op)
{
case ‘+’:
c=a+b;
printf(“Sum=%d\n”,c);
break;
case ‘-‘:
printf(“Subtraction\n”);
c=a-b;
printf(“Difference=%d\n”,c);
break;
case ‘‘: printf(“Multiplication\n”); c=ab;
printf(“Product=%d\n”,c);
break;

``````    case '/':
printf("Division\n");
c=a/b;
printf("Quotient=%d\n",c);
break;
case '%':
printf("Remainder\n");
c=a%b;
printf("Remainder=%d\n",c);
break;
default:
printf("Invalid Option\n");
break;
}    /*end of switch statement*/
}
while(1);    /*End of while*/``````

return 0;

}/End of main function/

OUTPUT:
Enter a and b:10 20

• Subtraction
• Multiplication
/ Division
% Remainder
E Exit
Multiplication
Product=200

• Subtraction
• Multiplication
/ Division
% Remainder
E Exit