c语言switch case语句例子是什么?

如题所述

c语言switch case语句例子如下:

#include <stdio.h>int main(){int a;printf("Input integer number:");scanf("%d",&a);if(a==1){printf("Monday\n")。

}else if(a==2){printf("Tuesday\n");}else if(a==3){printf("Wednesday\n");}else if(a==4){printf("Thursday\n");}else if(a==5)

{printf("Friday\n");}else if(a==6){printf("Saturday\n");}else if(a==7){printf("Sunday\n");}else{printf("error\n");}return 0;}

switch作为C语言程序语句

Switch用在编程中,如C语言中它经常跟Case一起使用,是一个判断选择代码。其功能就是控制流程流转的。

直线翻译:switch语句,即“切换”语句;case即“情况”。

switch语句的语法如下(switch,case,break和default是关键字):

switch ( 变量表达式 ){    case 常量1 :语句;break;    case 常量2 :语句;break;    case 常量3 :语句;break;    ...    case 常量n:语句;break;         default :语句;break;}

温馨提示:答案为网友推荐,仅供参考