Home / Programs / Program to display arithmetic operator using switch case
Programming Example

Program to display arithmetic operator using switch case

👁 5,811 Views
💻 Practical Program
📘 Step by Step Learning
Program to display arithmetic operator using switch case

Program Code

/* 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;
 }
 
}

Output

<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 . . .

Explanation

Program to display arithmetic operator using switch case

How to learn from this program

First read the algorithm, then study the program code line by line. After that, compare the code with the output and finally go through the explanation. This approach helps learners understand both the logic and the implementation properly.