calculator using switch
// calculator using switch case
#include <stdio.h>
int main()
{
float x, y;
int a;
printf("Enter x : \n");
scanf("%f", &x);
printf("Enter y : \n");
scanf("%f", &y);
printf("Enter 1 for addition : \n");
printf("Enter 2 for subtraction : \n");
printf("Enter 3 for multiplication : \n");
printf("Enter 4 for division : \n");
scanf("%d", &a);
switch(a)
{
case 1:
printf("x+y=%f\n", x+y);
break;
case 2:
printf("x-y=%f\n", x-y);
break;
case 3:
printf("x*y=%f\n", x*y);
break;
case 4:
printf("x/y=%f\n", x/y);
break;
default:
printf("This operation is invalid in this calculator.");
}
return 0;
}
Comments
Post a Comment