simple calculator using switch case.

 

....simple calculator using switch case...


//simple calculator using switch case

#include<stdio.h>
int main()
{
float a,b,result;
char op;
printf("Enter your first no.:");
scanf("%f", &a);

printf("Choose your operator(+,-,*,/):");
scanf(" %c", &op);

printf("Enter your Seccond no.:");
scanf("%f", &b);

switch(op)
{
    case '+':
    result = a+b;
    printf(" %.2f + %.2f = %0.2f", a,b,result);
    break;
    
    case '-':
    result =a-b;
    printf(".%.2f - %.2f = %.2f", a,b,result);
    break;
    
    case '*':
    result =a*b;
    printf("%.2f * %.2f = %.2f", a,b,result);
    break;
     case '/':
    result =a/b;
    printf("%.2f / %.2f = %.2f", a,b,result);
    break;
    
    default:
    printf("wrong input:");
    break;
}
return 0;
    
}

output: 

Enter your first no.:12
Choose your operator(+,-,*,/):/
Enter your Seccond no.:3
12.00 / 3.00 = 4.00

Post a Comment