c++作业-4

一、输出星号图

#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;  
}  


 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值