c语言:有12个彩球,其中3个为白色,3个为红色,6个为黑色,要求从中任取8个,问这种颜色的组合共有多少种

来源:百度知道 编辑:UC知道 时间:2024/09/20 02:31:01

有13种。
以下代码已经编译运行过

#include <stdio.h>
#include <conio.h>
void main(){
int cnt=0,i=0,j,k;
for(;i<=3;++i)
for(j=0;j<=3;++j)
for(k=2;k<=6;++k)
if(i+j+k==8){
printf("WHITE:%d,RED:%d,BLACK:%d\n",i,j,k);
++cnt;
}
printf("Press any key to Exit\n");
getch();
}

#include <stdio.h>
#include <conio.h>
void main(){
int cnt=0,i=1,j,k;
for(;i<=3;++i)
for(j=1;j<=3;++j)
for(k=1;k<=6;++k)
if(i+j+k==8){
printf("WHITE:%d,RED:%d,BLACK:%d\n",i,j,k);
++cnt;
}
printf("Press any key to Exit\n");
getch();
}
//The karma exists as we believe or not,now or later,here or there

3白3红2黑 3白2红3黑
2白3红3黑 3白1红4黑
1白3红4黑 2白6黑
3红5黑 2红6黑
1白1红6黑 2白2红4黑
3白3红2黑 3白5黑
3红5黑…