c中switch中有大于小于怎么表示

来源:百度知道 编辑:UC知道 时间:2024/06/23 13:21:02

使用多个case叠加即可。比如下面的代码,当输入字符为+、a、或者大写字母A时,都可以调用f_add()。

#include <stdio.h>
void f_add(void) {printf("execute + operation\n");}
void f_sub(void) {printf("execute - operation\n");}
void f_mul(void) {printf("execute * operation\n");}
void f_div(void) {printf("execute / operation\n");}
int main()

char ch;
scanf("%c", &ch);
switch (ch)
{
case '+':
case 'a':
case'A':
f_add(); break;
case '-':
case 's':
case 'S':
f_sub(); break;
case '*':
case 'm':
case 'M':
f_mul(); break;
case '/':
case 'd':
case 'D':