问题描述:一个口袋中放有12个球,已知其中三个是红的,三个是白的,六个是黑的,现从中任取八个,问共有多少种颜色搭配?
流程图:
伪代码:
num<-0
for i<-0 to 3
for j<-0 to 3
if 8-i-j>6
continue
else
k=8-i-j
num++
output i,j,k
output num
代码:
#include <iostream>
using namespace std;
int main()
{
int i,j,k,num=0;
for(i=0;i<=3;i++)
{
for(j=0;j<=3;j++)
{
if(8-i-j>6)
continue;
else
{
k=8-i-j;
num++;
cout<<"红"<<i<<","<<"白"<<j<<","<<"黑"<<k<<endl;
}
}
}
cout<<num<<"种";
}
标签:continue,++,else,num,打卡,cout From: https://www.cnblogs.com/chukjbgg333/p/17402879.html