// Simple calculator using switch...case statement in C programming.
# include <stdio.h>
int main()
{
char o;
float a,b;
printf("Enter operator either + or - or * or divide : ");
scanf("%c",&o);
printf("Enter First Value: ");
scanf("%f",&a);
printf("Enter Second Value: ");
scanf("%f",&b);
switch(o) {
case '+':
printf("%.1f + %.1f = %.1f",a, b, a+b);
break;
case '-':
printf("%.1f - %.1f = %.1f",a, b, a-b);
break;
case '*':
printf("%.1f * %.1f = %.1f",a, b, a*b);
break;
case '/':
printf("%.1f / %.1f = %.1f",a, b, a/b);
break;
default:
printf("Error! operator is not correct");
break;
}
return 0;
}
Output :
# include <stdio.h>
int main()
{
char o;
float a,b;
printf("Enter operator either + or - or * or divide : ");
scanf("%c",&o);
printf("Enter First Value: ");
scanf("%f",&a);
printf("Enter Second Value: ");
scanf("%f",&b);
switch(o) {
case '+':
printf("%.1f + %.1f = %.1f",a, b, a+b);
break;
case '-':
printf("%.1f - %.1f = %.1f",a, b, a-b);
break;
case '*':
printf("%.1f * %.1f = %.1f",a, b, a*b);
break;
case '/':
printf("%.1f / %.1f = %.1f",a, b, a/b);
break;
default:
printf("Error! operator is not correct");
break;
}
return 0;
}
Output :
কোন মন্তব্য নেই:
একটি মন্তব্য পোস্ট করুন