Program to display arithmetic operator using switch case

C Programming Language Decision Making of C Language (Article) Decision Making of C Language (Program)

5686

Program:

/* 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:

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

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

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

Output 4
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

This Particular section is dedicated to Programs only. If you want learn more about C Programming Language. Then you can visit below links to get more depth on this subject.