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

Program to display arithmetic operator using switch case

👁 5,815 Views
💻 Practical Program
📘 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;
 }
 
}

                        

🖥 Program 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
📚 Learning Subject

Master Programming Through Practical Examples

Improve your coding logic, problem-solving skills and programming confidence by practicing real-world examples with explanations.

🎯 How to learn from this example

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.

🔥 Practice suggestion

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.