第四次C++作业

一。图形输出

#include <iostream>
using namespace std;
int main( )
{
    int i,j,n=6;
    for(i=1;i<=n;++i)
    {
        for(j=1; j<=n-i; ++j)
            cout<<" ";
        for(j=1; j<=2*i-1; ++j)
            cout<<"*";
        cout<<endl;
    }
    for(i=1;i<=n-1;++i)
    {
        for(j=1; j<=i; ++j)
            cout<<" ";
        for(j=1; j<=2*(n-i)-1; ++j)
            cout<<"*";
        cout<<endl;
    }
    return 0;
}


二。穷举法百鸡问题问题

<pre name="code" class="cpp">#include <iostream>
using namespace std;
int main()
{
    int x,y,z;
    for(x=0;x<=20;x++;)
        for(y=0;y<=33;y++;)
           for;(z=0;z<=300;z++;)
    if(5*x+3*y+z/3==100 && x+y+z==100 && z%3==0)
    {
        cout<<"鸡翁"<<x<<"鸡母"<<y<<"鸡雏"<<z<<"只"<<endl;
    }
    return 0;
}


 三。穷举法都要学C 

#include<stdio.h>
int main()
{
	  int a;
	  int b;
	  int c;
	  int d;
      int l;
	  int m;
	  int n;
	  int flag=0;
	  for(a=1; a<3; a++)
	  {
	      for(b=1; b<10; b++)
		  {
			  if(a!=b)
			  {
				  for(c=1; c<10; c++)
				  {
				       if(c!=a && c!=b)
					   {
					      for(d=0; d<10; d++)
						  {
						      if(d!=c && d!=a && d!=b)
							  {
								  n=c*10+ d;
								  m=b*100+ c*10+ d;
								  l=a*1000+ b*100+ c*10+ d;
								  if(n+m+l==2008)
								  {
									  flag=1;
								      printf("都=%d  要=%d  学=%d  C=%d\n", a, b, c, d);
								      printf("都要学C=d%\n", l);
								      printf("  要学C=%d\n", m);
								      printf("    学C=%d\n", n);
								  }
							  }
						  }
					   }
				  }
			  }
		  }
	  }

	  if(flag==0)
	  {
	      printf("该题没有答案!\n");
	  }

      return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值