//enum枚举类型 #include<stdio.h> void enumTest(); void main() { enumTest();//枚举类型举例 printf(" 排列问题,5球取三球,不重色 "); enum color{red,yellow,blue,white,black}; int i,j,k,pri;//注意是int类型 int n,loop; n=0; for(i=red;i<=black;i++) for(j=red;j<=black;j++) if(i!=j) { for(k=red;k<=black;k++) if((k!=i)&&(k!=j)) { n=n+1; printf("%-4d",n); for(loop=1;loop<=3;loop++) { switch(loop) { case 1:pri=i;break; case 2:pri=j;break; case 3:pri=k;break; default:break; } switch(pri) { case 0:printf("%-10s","red");break; case 1:printf("%-10s","yellow");break; case 2:printf("%-10s","blue");break; case 3:printf("%-10s","white");break; case 4:printf("%-10s","black");break; default:break; } } printf(" "); } } printf(" toatal=%5d ",n); } //枚举类型小例子 void enumTest() { void showColor(int); enum color{red,green,blue,white,black}j,k;//枚举元素,枚举常量从0开始编号,递增 int i=(enum color)0; j=(enum color)1; k=(enum color)2; showColor(i); showColor(j); showColor(k); for(i=red;i<=black;i++)//i不能定义为enum color类型,若定义为此类型,i++报错 { printf("i=%d ",i); showColor(i); } enum week{sunday=1,monday,tuesday}w;//递增编号 w=monday; printf("monday=%d ",w); } void showColor(int n) { printf("%d ",n); switch(n) { case 0:printf("red ");break; case 1:printf("green ");break; case 2:printf("blue ");break; case 3:printf("white ");break; case 4:printf("black ");break; default:break; } }