简单的四则运算计算器
#include<stdio.h>
#include<stdlib.h>
int main()
{
double x1, x2, answer;
char x;
printf("--------------------------------------\n");
printf("-----------四则计算器----------------\n");
printf("请输入计算表达式 (如 2+2)\n");
scanf("%lf%c%lf", &x1, &x, &x2);
switch (x)
{
case '+':
answer = x1 + x2;
break;
case '-':
answer = x1 - x2;
break;
case '*':
answer = x1 * x2;
break;
case '/':
answer = x1 / x2;
break;
default:
printf("你输入的符号有误,请重新输入");
break;
}
printf("%.2lf %c %.2lf = %.2lf", x1, x, x2, answer);
}