共有红黄绿蓝白黑六个球,每次依次抓取四个球,有多少种取法,并将每种取法打印出来
#include<stdio.h>main()
{
enum color{red,yellow,green,blue,white,black}; //共有红黄绿蓝白黑六个球,每次依次抓取四个球,有多少种取法,并将每种取法打印出来
enum color i,j,k,l,c;
int n=0,loop;
for(i=red;i<=black;i++)
for(j=i+1;j<=black;j++)
for(k=j+1;j<=black;k++)
for(l=k+1;l<=black;l++)
{
n++;
printf("%d: ",n);
for(loop=1;loop<=4;loop++)
{
switch(loop)
{
case 1:c=i; break;
case 2:c=j; break;
case 3:c=k; break;
case 4:c=l; break;
}
switch(c)
{
case red: printf("% -10s","red"); break;
case yellow: printf("% -10s","yellow"); break;
case green: printf("% -10s","green"); break;
case blue: printf("% -10s","blue"); break;
case white: printf("% -10s","white"); break;
case black: printf("% -10s","black"); break;
}
}
printf("\n");
}
printf("共有%d种取法!\n",n);
} //觉得思路没问题,最后编译结果出不来 应该是15种,请大神指教!!!