枚举类型问题
这是一道枚举题.五种颜色每次三个不同色,看能有多少次组合.我没明白为何 i 只循环一次,怎么做到的? ,j 循环20次,又是怎么做到的?main()
{
enum color {red,yellow,blue,white,black};
enum color i,j,k,pri;
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 red:printf("%-10s","red");break;
case yellow:printf("%-10s","yellow");break;
case blue:printf("%-10s","blue");break;
case white:printf("%-10s","white");break;
case black:printf("%-10s","black");break;
}
}
printf("\n");
}
}
printf("\ntotal:%5d\n",n);
}