In this tutorial, we are going to write a C Program to display arithmetic operations using a switch case in C Programming with practical program code and step-by-step full complete explanation.

C Program to display arithmetic operations using a switch case


C Program to display arithmetic operations using a switch case

#include<stdio.h>
#include<conio.h>

void main()
{
	int a,b,n,s,m,su,d;

	clrscr();

	printf("Enter two Numbers: ");
	scanf("%d%d",&a,&b);
	printf("Enter 1 for sum\n 2 for multiply\n 3 for subtraction\n 4 for divison: ");
	scanf("%d",&n);

	switch(n)
	{
	case 1:
	s = a+b;
	printf("sum=%d",s);
	break;
	case 2:
	m = a*b;
	printf("multiply=%d",m);
	break;
	case 3:
	su = a-b;
	printf("subtraction=%d",su);
	break;
	case 4:
	d = a/b;
	printf("division=%d",d);
	break;
	default:
	printf("Wrong input");
	break;
	}

	getch();
}


Output

Enter two Numbers: 8
4
Enter 1 for sum
2 for multiply
3 for subtraction
4 for division: 1
sum = 12