A Program That Explains The Use of Switch Case in C-Programing Language
Procedure:
Open your C program Software App such as CppDroid, DveC++ etc.
Write in the Syntax Below
//program that would Divide,Add and Subtract number using switch statement
#include<stdio.h>
#include<stdlib.h>
int main(){
float ans;
float value1,value2;
int option;
printf("Enter the values: ");
scanf("%f%f",&value1,&value2);
printf("Enter 1 for addition\n");
printf("Enter 2 for subtraction\n");
printf("Enter 3 for division\n");
printf("Enter 4 for mutiplication\n");
scanf("%d",&option);
switch(option){
case 1:
ans=value1+value2;
printf("%f+%f=%f",value1,value2,ans);
break;
case2:
ans=value1-value2;
printf("%f-%f=%f",value1,value2,ans);
case 3:
ans=value1/value2;
printf("%f/%f=%f",value1,value2,ans);
case 4:
ans=value1*value2;
printf("%f*%f=%f",value1,value2,ans);
break;
default:
printf("Enter the write option");
break;
}
}
The Result of the Program.
1:When you Chose 1;The Additional case is Implemented
2: When you Choose 2; The Subtraction case Is Implemented.
3:When you Choose 3;The Division case is Implemented.
4:When you Choose 4; The Multiplication case is Implemented.
Comments