/* Program to display arithmetic operator using switch case.
Author: Atnyla Developer */
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,n,s,m,su,d;
printf("enter two no's : ");
scanf("%d%d",&a,&b);
printf("enter 1 for sum\n2 for multiply\n3for subtraction\n4 for division: \n");
printf(".....................");
scanf("%d",&n);
switch(n)
{
case 1:
s=a+b;
printf("sum=%d \n",s);
break;
case 2:
m=a*b;
printf("multiply=%d \n",m);
break;
case 3:
su=a-b;
printf("subtraction=%d \n",su);
break;
case 4:
d=a/b;
printf("divission=%d \n",d);
break;
default:
printf("wrong input \n");
break;
}
}
<b>Output 1</b>
enter two no's : 2 5
enter 1 for sum
2 for multiply
3for subtraction
4 for division:
.....................1
sum=7
Press any key to continue . . .
<b>Output 2</b>
enter two no's : 2 5
enter 1 for sum
2 for multiply
3for subtraction
4 for division:
.....................2
multiply=10
Press any key to continue . . .
<b>Output 3</b>
enter two no's : 2 5
enter 1 for sum
2 for multiply
3for subtraction
4 for division:
.....................3
subtraction=-3
Press any key to continue . . .
<b>Output 4</b>
enter two no's : 8 2
enter 1 for sum
2 for multiply
3for subtraction
4 for division:
.....................4
divission=4
Press any key to continue . . .
First understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.
Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.