#include <stdio.h>
int 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++) //外循环使i的值从red变为black//
for(i = red;j<=black;j++) //中循环使j的值从red变为black//
if(i!=j) //判断二球是否同色,若不同色执行内循环//
{for(k=red;k<=black;k++) //内循环使K的值从red变为black//
if((k!=i)&&(k!=j)) //判断三球不同色//
{
n = n+1; //符合条件n值+1//
printf("%-4d",n); //输出当前是第几个符合条件的组合//
for(loop=1;loop<=3;loop++) //先后对三个球分别处理//
{
switch(loop) //loop的值从1变到3//
{
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;
default:break;
}
}
printf("\n");
}
}
printf("\ntotal:%5d\n",n);
return 0;
}
标签:口袋,case,pri,C语言,break,%-,printf,red,个球 From: https://blog.51cto.com/u_15865347/5908560