一. 百钱百鸡问题
#include <iostream>
using namespace std;
int main( )
{
int x,y,z;
cout<<"百钱百鸡问题中可以有的办法有这些:"<<endl;
for(x=0;x>=0&&x<=20;x++)
for(y=0;y>=0&&y<=33;y++)
for(z=0;z>=0&&z<=100;z++)
if(x+y+z==100&&5*x+3*y+z/3.0==100)
cout<<"鸡翁"<<x<<"只"<<","<<"鸡母"<<y<<"只"<<","<<"鸡雏"<<z<<"只"<<"。"<<endl;
}
二.乘法口诀表
#include <iostream>
using namespace std;
int main( )
{
int i,j;
for(i=1;i<=9;i++)
{
for(j=1;j<=i;j++)
cout<<j<<"*"<<i<<"="<<j*i<<"\t";
cout<<endl;}
}
三. 输出星号图
#include <iostream>
using namespace std;
int main( )
{
int i,j,p,k;
cout<<" "<<"*"<<endl;
for(i=2;i<=5;i++)
{
for(j=1;j<=6-i;j++)
{cout<<" ";}
cout<<"*";
for(p=1;p<=2*i-3;p++)
cout<<" ";
cout<<"*"<<endl;}
for(k=1;k<=11;k++)
cout<<"*";
}