ios学习Day3xiawu

switch

#include <stdio.h>

int main(int argc, char * argv[])
{
    int i;
    scanf("%d",&i);
    switch(i)
    {
        case 1:
        {printf("");
            break;
        }
        case 2:
        {
            printf("");
            break;
        }
        case 3:
        {
            printf("");
            break;
        }
            
        case 4:
        { printf("");
        }
        default:
            break;
      

}
}

多个case可以运行一个语句块

case中定义变量需要加{};

枚举类型(enum)

1

提高程序的可读性,本质是整形,用枚举类型代表整数常量;

enum Season

{
spring,
summer,
autumn,
winter
}
//默认从零开始
enum Season aeason=0;
scanf("%d,&season");
switch(season)
{
case spring:
{
printf("spring");
}
case summer:
{
printf("spring");
}
case autumn:
{
printf("autumn");
]

}
#include <stdio.h>
enum Season

{
    spring=1,
    summer,
    autumn,
    winter
};
typedef enum Season myseason ;//为现有类型创建一个别名
int main(int argc, char * argv[])
{
        //默认从零开始
    myseason season=0;
    scanf("%d",&season);
    switch(season)
    {
        case spring:
        {
            
            printf("spring");
            break;        }
        case summer:
            
        {
            printf("summer");
            break;
        }
        case autumn:
        {
            printf("autumn");
            break;
            
        }
            case winter:
        {
            printf("winter");
            break;
        }
            default:
        {
            printf("未知");
        }
            


}
}

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

ios学习Day3xiawu,布布扣,bubuko.com

ios学习Day3xiawu

上一篇:推荐——Monkey《大话 app 测试——Android、iOS 应用测试指南》


下一篇:转游戏开发做的第一款手机网游的经历和体会