当前位置: 代码迷 >> 综合 >> day08 c语言 枚举类型
  详细解决方案

day08 c语言 枚举类型

热度:53   发布时间:2024-01-17 14:39:57.0

C语言

枚举类型

#include<stdio.h>
#include<stdlib.h>
#include<time.h>int main (void)
{
    enum Week {
    sun, mon,tue, wed, thu, fri, sat};enum Week today;struct tm *p;time_t t ;time(&t);p = localtime(&t);today = p->tm_wday;switch(today){
    case mon:case tue:case wed:case thu:case fri:printf("干活!T_T\n");break;case sat:case sun:printf("放假!^_^\n");break;default: printf("Error\n");}
}
#include<stdio.h>
#include<stdlib.h>
#include<time.h>int main (void)
{
    //若在中间定义,开头变量任从0开始enum Color {
    red = 10, green, blue};enum Color rgb;for(rgb = red; rgb <=blue; rgb++){
    printf("rgb is %d\n",rgb);}return 0;
}