switch

#include <stdio.h>

int main(int argc, char * argv[])
{
int i;
scanf("%d",&i);
switch(i)
{
case :
{printf("春");
break;
}
case :
{
printf("夏");
break;
}
case :
{
printf("秋");
break;
} case :
{ 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=,
summer,
autumn,
winter
};
typedef enum Season myseason ;//为现有类型创建一个别名
int main(int argc, char * argv[])
{
//默认从零开始
myseason season=;
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("未知");
} }
}

最新文章

  1. C# 调用百度翻译Api
  2. tomcat组成及工作原理
  3. JavaScript之模块化编程
  4. JavaScriptの例
  5. Hadoop源代码导入Eclipse
  6. 3384/1750: [Usaco2004 Nov]Apple Catching 接苹果
  7. [Swift]LeetCode564. 寻找最近的回文数 | Find the Closest Palindrome
  8. Oracle :多表更新多个字段
  9. IIS下MySQL停止和启动的方法
  10. Hass.io: add-on Samba
  11. VuePress
  12. C#学习笔记(35)——事件做的登录案例
  13. 逻辑回归(logic regression)的分类梯度下降
  14. FireDAC 下的 Sqlite [1] - 前言
  15. linux 安装 vsftpd服务
  16. 测试用例Excel模板For Quality Center
  17. Android --------------------ActionBar 与 ViewPager 和 ActionTab 切换 的源代码实现
  18. Codeforces Round #303 (Div. 2) A. Toy Cars 水题
  19. makefile .phony targets
  20. Sort函数(C++)

热门文章

  1. javascript学习笔记(1) 简单html语法
  2. SQL Server 一些重要视图2
  3. 转:Http头介绍:Expires,Cache-Control,Last-Modified,ETag
  4. cygwin在Windows8.1中设置ssh的问题解决
  5. poj2140---herd sums
  6. 网易云课堂_C语言程序设计进阶_第6周:程序结构
  7. 使用sphinx索引mysql数据
  8. 简单C#文字转语音
  9. HTML之学习笔记(七)列表
  10. Spring MVC 完整示例