栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

【C++】循环练习作业:打印图形+九九乘法表(附加:判断闰年问题+三个数排序输出问题)

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

【C++】循环练习作业:打印图形+九九乘法表(附加:判断闰年问题+三个数排序输出问题)

题目如下 题目01

题目02

题目03

题目04

题目05

题目06

ex04_10

编程求解问题,若一头小母牛,从出生起第四个年头开始每年生一头母牛,按此规律,第n年时有多少头母牛。

题目07

题目08

实现代码
#include 
#include 

using namespace std;

void test_ex04_08_01()
{

    for (int i = 9, j = 1; i >= 0; i--, j = j + 2)
    {
        for (int m = 0; m < i; m++)
            cout << "  ";
        for (int n = 0; n < j; n++)
            cout << "# ";
        cout << endl;
    }
}

void test_ex04_08_02()
{

    for (int i = 8, j = 17; i > 0; i--, j--)
    {
        for (int m = 0; m < 8 - i; m++)
            cout << " ";
        for (int n = 0; n < j; n++)
            cout << "# ";
        cout << endl;
    }
}

void test_ex04_09_01()
{

    cout << "*";
    for (int heng = 1; heng < 10; heng++)
    {
        cout << "t" << heng;
    }
    cout << endl;
    cout << "---------------------------------------------------------------------------" << endl;
    for (int i = 1, head = 1; i <= 9; i++, head++)
    {
        cout << head << "t";
        for (int j = 1; j <= 9; j++)
        {
            cout << head * j << 't';
        }
        cout << endl;
    }
}

void test_ex04_09_02()
{

    cout << "*";
    for (int heng = 1; heng < 10; heng++)
    {
        cout << "t" << heng;
    }
    cout << endl;
    cout << "---------------------------------------------------------------------------" << endl;
    for (int i = 1, head = 1; i <= 9; i++, head++)
    {
        cout << head << "t";
        for (int j = 1; j <= i; j++)
            cout << i * j << 't';

        cout << endl;
    }
}

void test_ex04_09_03()
{

    cout << "*";
    for (int heng = 1; heng < 10; heng++)
    {
        cout << "t" << heng;
    }
    cout << endl;
    cout << "---------------------------------------------------------------------------" << endl;
    for (int i = 1, head = 1; i <= 9; i++, head++)
    {
        cout << head << "t";
        for (int j = 1; j <= 9; j++)
        {
            if (j < i)
                cout << 't';
            else
                cout << i * j << 't';
        }
        cout << endl;
    }
}

int func_ex04_10(int n)
{
    if (n <= 3) //数据校验有待完善
        return 1;
    else
        return func_ex04_10(n - 1) + func_ex04_10(n - 3);
}

void test_ex04_10()
{
    cout << "请输入年份n,将计算求出第n年时有多少头母牛:" << endl;
    int n;
    cin >> n;
    cout << "第" << n << "年时有 " << func_ex04_10(n) << " 头母牛: " << endl;
}

int func_unit3_assign1(int year)
{
    if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0)
        return 1;
    return 0;
}

void test_unit3_assign1()
{
    cout << "Enter a year : ";
    int year;
    cin >> year;
    cout << endl;
    int leap = func_unit3_assign1(year);
    if (leap)
        cout << year << " is a leap year." << endl;
    else
        cout << year << " is not a leap year." << endl;
}

void test_unit3_assign2()
{
    cout << "请输入三个数字 : " << endl;
    int x, y, z;
    cin >> x >> y >> z;
    cout << endl;
    int total = x + y + z;
    int max_value = max(max(y, z), max(y, x));
    int min_value = min(min(y, z), min(y, x));
    cout << "max = " << max_value << endl;
    cout << "mid = " << total - max_value - min_value << endl;
    cout << "min = " << min_value << endl;
}




int main()
{

    cout << "-------------------begin--------------------------n" << endl;

    //    test_ex04_08_01();
    //    test_ex04_08_02();
    //    test_ex04_09_01();
    //    test_ex04_09_02();
    //    test_ex04_09_03();
    //    test_ex04_10();
    //    test_unit3_assign1();
       test_unit3_assign2();


    cout << "n--------------------end----------------------------" << endl;
    return 0;
}


实现效果






转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/429490.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号