<span style="font-family: Arial, Helvetica, sans-serif; font-size: 12px;"><span style="margin: 0px; padding: 0px; color: rgb(85, 85, 85); font-size: 15px; line-height: 35px; font-family: 宋体;">三色球问题:若一个口袋中放有</span><span style="margin: 0px; padding: 0px; color: rgb(85, 85, 85); font-size: 15px; line-height: 35px; font-family: 'Times New Roman';">12</span><span style="margin: 0px; padding: 0px; color: rgb(85, 85, 85); font-size: 15px; line-height: 35px; font-family: 宋体;">个球,其中有</span><span style="margin: 0px; padding: 0px; color: rgb(85, 85, 85); font-size: 15px; line-height: 35px; font-family: 'Times New Roman';">3</span><span style="margin: 0px; padding: 0px; color: rgb(85, 85, 85); font-size: 15px; line-height: 35px; font-family: 宋体;">个红的。</span><span style="margin: 0px; padding: 0px; color: rgb(85, 85, 85); font-size: 15px; line-height: 35px; font-family: 'Times New Roman';">3</span><span style="margin: 0px; padding: 0px; color: rgb(85, 85, 85); font-size: 15px; line-height: 35px; font-family: 宋体;">个白的和</span><span style="margin: 0px; padding: 0px; color: rgb(85, 85, 85); font-size: 15px; line-height: 35px; font-family: 'Times New Roman';">6</span><span style="margin: 0px; padding: 0px; color: rgb(85, 85, 85); font-size: 15px; line-height: 35px; font-family: 宋体;">个黒的,问从中任取</span><span style="margin: 0px; padding: 0px; color: rgb(85, 85, 85); font-size: 15px; line-height: 35px; font-family: 'Times New Roman';">8</span><span style="margin: 0px; padding: 0px; color: rgb(85, 85, 85); font-size: 15px; line-height: 35px; font-family: 宋体;">个共有多少种不同的颜色搭配?</span>
</span>
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 12px;">#include <iostream> </span>
using namespace std;
int main()
{
int i,j,k;
cout<<"若一个口袋中放有12个球,其中有3个红的。3个白的和6个黒的,从中任取8个不同的种颜色搭配的方案有:"<<endl;
for(i=0;i<=3;i++)
for(j=0;j<=3;j++)
{
k=8-i-j;
if (k<=6)
cout<<"红色球"<<i<<",白色球"<<j<<",黑色球"<<k<<""<<endl;
}
return 0;
}
【项目3:乘法口诀表】编程序,输出一个乘法口诀表
<span style="font-family:Arial;color:#333333;"><span style="font-size: 14px; line-height: 26px;"></span></span><pre name="code" class="cpp">#include<iostream>
using namespace std;
int main()
{
int i,j;
for(i=1;i<=9;i=i+1)
{
for(j=1;j<=i;j=j+1)
{ cout<<i<<"*"<<j<<"="<<i*j<<" ";}
cout<<endl;
}
return 0;
}
【项目
6
:输出星号图】编程序输出。
<span style="font-family:宋体;color:#555555;"><span style="font-size: 15px; line-height: 35px;"></span></span><pre name="code" class="cpp">#include<iostream>
using namespace std;
int main()
{
int i,j;
for(i=1;i<=5;i=i+1)
{
cout<<" ";
}
cout<<"*"<<endl;
for(i=2;i<=5;i=i+1)
{
for(j=0;j<=5-i;j=j+1)
{
cout<<" ";
}
cout<<"*";
for(j=0;j<2*i-3;j=j+1)
{
cout<<" ";
}
cout<<"*"<<endl;
}
for(j=0;j<=2*(i-1);j=j+1)
{
cout<<"*";
}
cout<<endl;
return 0;
}