一、输出星号图
#include <iostream.h>
void main()
{
int i,j;
cout<<" *"<<endl;
for(i=0;i<4;i++)
{
for(j=0;j<4-i;j++)
cout<<" ";
cout<<"*";
for(j=0;j<2*i+1;j++)
cout<<" ";
cout<<"*";
cout<<endl;
}
cout<<"***********"<<endl;
}
二、买鸡问题
#include <iostream>
using namespace std;
int main()
{
int x,y,z,count=0;
cout<<" 翁,母,雏各:"<<endl;
for(x=0;x<=20;x++)
for(y=0;y<=33;y++)
for(z=0;z<=300;z++)
if(x+y+z==100&&5*x+3*y+z/3.0==100)
{
++count;
cout<<count<<"、"<<"鸡翁有:"<<x<<"鸡母有:"<<y<<"鸡雏有:"<<z<<endl;
}
return 0;
}
#include <iostream>
using namespace std;
int main()
{
int i,j,k;
cout<<" 不同的颜色搭配有:"<<endl;
for(i=0;i<=3;i++)
for(j=0;j<=3;j++)
for(k=0;k<=6;k++)
if(i+j+k==8)
{
cout<<"红球:"<<i<<"白球:"<<j<<"黑球:"<<k<<endl;
}
return 0;
}