参考代码:
int main() { int a,b,c; char s; scanf("%d%d",&a,&b); getchar(); s=getchar(); switch(s) { case '+':c=a+b;break; case '-':c=a-b;break; case '*':c=a*b;break; case '/':c=a/b;break; case '%':c=a%b;break; } printf("%d\n",c); return 0; }
这里为什么不能用scanf(%c)来输入字符?
0.0分
2 人评分
#include<stdio.h> #include<string.h> int main() { int a, b; int c; char s; scanf_s("%d %d %s", &a, &b,&s); switch (s){ case '+':c = a + b; break; case '-':c = a - b; break; case '*':c = a * b; break; case '/':c = a / b; break; case '%':c = a % b; break; } printf("%d\n", c); return 0; }