Answer:
Following are the code in C language
#include <stdio.h> // header file
int main() // main method
{
float f1; // variable declarartion
float x,y; //variable declarartion
int option;//variable declarations
printf("Enter Two numbers:");
scanf("%f%f",&x,&y);// input two number
printf("Choose : 1: For add 2: For Subtract 3: for multiply 4: for divide");
scanf("%d",&option); //read the choice
switch(option)
{
case 1: // for addition
printf("%4f",x+y);
break;
case 2:// for subtraction
printf("%4f",x-y);
break;
case 3: //for multiply
printf("%4f",x*y);
break;
case 4: // for division
f1=x/y;
printf("%4f",f1);
break;
default: ////for invalid choice
printf("Invalid choice") ;
}
return 0;
}
Explanation:
In this program we taking a two input from user of float types after taking input,the switch statement is used case 1 for addition,case 2 for subtraction case 3 for multiplication,case 4 for division and default for invalid choice .
Output
Enter Two numbers:2.5
2.5
Choose : 1: For add 2: For Subtract 3: for multiply 4: for divide:4
1.000000