(switch 语句)c语言题

Python023

(switch 语句)c语言题,第1张

#include <stdio.h>

int main () {

    int n

    printf("读入一个整数 ")

    scanf("%d", &n)

    switch(n) {

    case 1: printf("第一个福娃名字\n") break

    case 2: printf("第二个福娃名字\n") break

    case 3: printf("第三个福娃名字\n") break

    case 4: printf("第四个福娃名字\n") break

    case 5: printf("第五个福娃名字\n") break

    default: printf("北京欢迎你\n") 

    }

    return 0

}

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

#include <stdio.h>int main(){int aprintf("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}