![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg-kv0sA2fCrJuba5KFyl0jNoiZR4KDWSm_U18tja2eTGLKgpmgx9kLLab6exLUUJ1fKC0SggOykKEUe3hyUuZFdpXY3_1ERZbadMMA-5sng6YqWBYp6FrGsedWTUqmUyifijrvjXole_u3/s640/programs+to+do+all+arithmetic+operation+Using+Switch+Case+.jpg)
A control statement which allows us to make decision from member of choice is called switch-case-default.these three keywords go together and make a control statement. Switch statement has more than two options,these options are called cases.
Program:
//C Program to Perform Arithmetic Operation Using Switch Case by Slashmycode.com
#include<stdio.h>
#include<conio.h>
void main()
{
int num1,num2,choice;
printf("\n 1.Addition \n 2.Subtraction \n 3.Multiplication \n 4.Division");
printf("\nEnter the choice\t");
scanf("%d",&choice);
printf("Enter the first number");
scanf("%d",&num1);
printf("Enter the second number");
scanf("%d",&num2);
switch(choice)
{
case 1:
printf("The addition of %d + %d = %d",num1,num2,num1+num2);
break;
case 2:
printf("The subtraction of %d - %d = %d",num1,num2,num1-num2);
break;
case 3:
printf("The multiplication of %d * %d = %d",num1,num2,num1*num2);
break;
case 4:
printf("The division of %d / %d = %d",num1,num2,num1/num2);
break;
default:
printf("The choice is invalid");
}
//C Program to Perform Arithmetic Operation Using Switch Case by Slashmycode.com
getch();
}
Algorithm:
1. Start
2. Define a,b,c,d
3. Give choices Addition,Subtraction,Multiplication,Division
4. Enter choice
5. Enter Two Numbers
6. Check for choice
7. If choice==1
printf num1+num2
step 12
else step 8
8. If choice==2
printf num1-num2
step 12
else step 9
9. If choice ==3
printf num1*num2
step 12
else step 10
10. If choice==4
printf num1/num2
step 12
else step 11
11. Choice is invalid
12. Stop
No comments:
Post a Comment
Feel free to ask us any question regarding this post