arithmetic operation using switch case statement

Write a program to perform arithmetic operation using switch case statement.


Source code:

#include<stdio.h>
#include<conio.h>
void main()
{
	int a,b;
	char ch;
	clrscr();
	printf("Enter the value of a:");
	scanf("%d",&a);
	printf("Enter the value of b:");
	scanf("%d",&b);

	printf("+.Addition \n");
	printf("-.Subtraction \n");
	printf("*.Multiplication \n");
	printf("/.Division \n");

	printf("Enter your choice:");
	scanf("%c",&ch);

	switch(ch)
	{
		case '+':
			printf("Addition of two no is:", a+b);
			break;
		case '-':
			printf("Subtraction of two no is:",a-b);
			break;
		case '*':
			printf("Multiplication of two no is:",a*b);
			break;
		case '/':
			printf("Division of two no is:",a/b);
			break;

	}
	getch();

}

Output:
Enter the value of a: 10
Enter the value of b: 20

+. Addition
-.  Subtraction
*. Multiplication
/. Division

Enter your choice:
+

Addition of two no is: 30

Leave a Reply

Your email address will not be published. Required fields are marked *