int main() { char c; c = getchar();
switch (c) //参数只能是整型变量
{
case '1':
printf("OK\n");
break;//switch遇到break就中断了
case '2':
printf("not OK\n");
break;
default://如果上面的条件都不满足,那么执行default
printf("are u ok?\n");
}
return 0;
}
```cpp
#include <stdio.h>
#include <stdbool.h>
#define ADD '+'
#define SUB '-'
#define MULTIPLY '*'
#define DIVIDE '/'
#define REM '%'
int main() {
int left;
int right;
while (true) {
char operator;
printf("Please input an expression: \n");
scanf("%d %c %d", &left, &operator, &right);
int result;
switch (operator) {
case ADD:
result = left + right;
break;
case SUB:
result = left - right;
break;
case MULTIPLY:
result = left * right;
break;
case DIVIDE:
result = left / right;
break;
case REM:
result = left % right;
break;
default:
printf("Unsupported operation: %c\n", operator);
return 1;
}
printf("Result: %d\n", result);
}
return 0;
}