c++作业4

项目6:输出星号图

#include <iostream.h>         
void main()
{  
    int i,j;   
	for(j=1; j<=5; j++) 
        cout<<" ";  
        cout<<"*"<<endl;  
    for(i=2;i<=5;++i)
    {  
        
        for(j=1;j<=6-i;j++)
	    cout<<" ";
            cout<<"*";
	for(j=1; j<=2*i-3;j++) 
            cout<<" ";  
            cout<<"*"<<endl; 
    }  
    for(j=1; j<=2*6-1;j++)   
        cout<<"*";  
        cout<<endl; 
}


项目7:(1)百钱百鸡问题

#include <iostream.h>
void main()
{
	int x,y,z,a,b;
	for(x=0;x<=20;x++)
	for(z=0;z<=100;z++)
	for(y=0;y<=33;y++)
	if(z%3==0&&5*x+3*y+z/3==100&&x+y+z==100)
    cout<<"鸡翁"<<x<<"只,"<<"鸡母"<<y<<"只,"<<"鸡雏"<<z<<"只。"<<endl;
}


项目7:(3)三色球问题

#include <iostream.h>
void main()
{
	int x,y,z;
        for(x=0;x<=3;x++)
	for(y=0;y<=3;y++)
	for(z=0;z<=6;z++)
	if(x+y+z==8)
	cout<<"红球"<<x<<"个,"<<"白球"<<y<<"个,"<<"黑球"<<z<<"个。"<<endl;
}



你可能感兴趣的:(c++作业4)