已經測試,執行正常,先輸入兩個數,然後輸入+-*/中的一個:接著就有結果
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
float a, b;
char c;
float res;
scanf("%f %f\n", &a, &b);
c = getchar();
switch (c)
case "+":
res = a + b;
break;
case "-":
res = a - b;
case "*":
res = a * b;
case "/":
res = a / b;
default:
printf("input error\n");
}
printf("result is: %f\n", res);
return 0;
已經測試,執行正常,先輸入兩個數,然後輸入+-*/中的一個:接著就有結果
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
float a, b;
char c;
float res;
scanf("%f %f\n", &a, &b);
c = getchar();
switch (c)
{
case "+":
res = a + b;
break;
case "-":
res = a - b;
break;
case "*":
res = a * b;
break;
case "/":
res = a / b;
break;
default:
printf("input error\n");
}
printf("result is: %f\n", res);
return 0;
}