C++第4作业

1、计算机解奥数

#include <iostream>
using namespace std;
int main()
{
    int e,b,c,d;
    int  x,u,v,y;
    for(b=0; b<=2; b++)
        for(c=0; c<=9; c++)
            for(d=0; d<=9; d++)
                for(e=0; e<=9; e++)
                {
                    x=d*10+e;
                    u=c*100+d*10+e;
                    v=b*1000+c*100+d*10+e;
                    y=x+u+v+e;
                    if(y==2008&&e!=c&&e!=b&&e!=d)
                        cout<<"都:"<<b<<"\t"<<"要:"<<c<<"\t"<<"学:"<<d<<"\t"<<"C:"<<e<<endl;
                }
    return 0;
}
运行结果


2、百钱百鸡问题

#include <iostream>
using namespace std;
int main()
{
    int a,b,c;
    int n=0;
    for(a=3; a>=3&&a<=300; a+=3)
        for(b=0; b<=33; b++)
            for(c=0; c<=20; c++)
                if(a/3+3*b+5*c==100&&a+b+c==100)
                {
                    n++;
                    cout<<"第"<<n<<"种:\t"<<"雏鸡"<<a<<"个,母鸡"<<b<<"个,公鸡"<<c<<"个\n";
                }
    cout<<"共有"<<n<<"种\n";
    return 0;
}

运行结果




3、输出星形图

#include <iostream>
using namespace std;
int main()
{
    int a,b,c,d,e;
    for(d=1; d<=5; d++)
        cout<<" ";
    cout<<"*";
    cout<<endl;
    for(a=1; a<=4; a++)
    {
        for(b=1; b<=5-a; b++)
            cout<<" ";
        cout<<"*";
        for(c=1; c<=2*a-1; c++)
            cout<<" ";
        cout<<"*";
        cout<<endl;
    }

    for(e=1; e<=11; e++)
        cout<<"*";
    return 0;
}



运行结果



4、九九乘法表

#include <iostream>
using namespace std;
int main()
{
    int a,b;
    for(a=1; a<=9; a++)
    {
        for(b=1; b<=a; b++)

            cout<<b<<"x"<<a<<"="<<a*b<<"\t";

        cout<<endl;
    }

    return 0;
}


运行结果


评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值