示例代码:
if else :语句
- char c;
- scanf("%c",&c); 输入一个char类型字符赋值给c
- if('0'<=c&&c<='9') printf("c=%c--->%c",c,'A'); //判断是数字输出A
- else if('A'<=c&&c<='Z') printf("c=%c--->%c",c,'B'); //判断是大写字母输出B
- else if('a'<=c&&c<='z') printf("c=%c--->%c",c,'C'); //判断是小写字母输出C
- else if(c==' ') printf("c=%c--->%c",c,'D'); //判断是空白符输出D
- else if(c=='\n') printf("c=%c--->%c",c,'E'); //判断是回车符输出E
- else printf("c=%c--->%c",c,'F'); //其他字符输出F
switch:语句
- int x;
- printf("Please input integer number(1-7):----->");
- scanf("%d",&x); //输入一个十进制数:赋值给x
- switch(x){ //判断x
- case 1: //x是1,输出Monday
- printf("Monday\n");
- break;
- case 2: //x是2,输出Tuesday
- printf("Tuesday\n");
- break;
- case 3: //x是3,输出Wednesday
- printf("Wednesday\n");
- break;
- case 4: //x是4,输出Thursday
- printf("Thursday\n");
- break;
- case 5: //x是5,输出Friday
- printf("Friday\n");
- break;
- case 6: //x是6,输出Staurday
- printf("Saturday\n");
- break;
- case 7: //x是7,输出Sunday
- printf("Sunday\n");
- break;
- default: //默认值
- printf("you are wrong!\n");
- }