1.问题描述
一个口袋中放有12个球,已知其中3个是红的,3个是白的,6个是黑的,现从中任
取8个,问共有多少种可能的颜色搭配?
2.代码
#include <stdio.h>
int main()
{
int red = 0, white = 0, black = 0;
int cnt = 0;
for(red = 0; red <= 3; red++)
for(white = 0; white <=3; white++)
for(black = 0; black <= 6; black++)
if(red + white + black == 8)
{
printf("%-2d --- %d个红球,%d个黑球,%d个黑球\n",
++cnt, red, white, black);
}
printf("总共有%d种搭配.\n", cnt);
return 0;
}