zoukankan      html  css  js  c++  java
  • 课堂测试小程序

    题目:随机数的四则运算

    思路:取两个随机整数,将运算符号放在一个数组里,再取一个随机数,整除4,通过余数来选取预算符号。真分数的四则运算,要取四个随机整数,并进行大小判断,真分数的分母要大于其分子。

    代码:

    #include<iostream>
    #include<time.h>
    using namespace std;
    void main()
    {
        srand(time(NULL));
        for (int i = 1; i <= 30; i++)
        {
            int a = rand()%25+1;
            int b = rand()%25+1;
            int c = rand() % 25 + 1;
            int d = rand() % 25 + 1;
            int e = a % 2;
            int f = b % 4;
            int x[4] = { '+', '-', '*', '/' };
            int y = 0;
            if (e == 1 && b < a&&d < c)
            {
                if (f == 1)

                    cout << b << '/' << a << ' ' << '+' << ' ' << d << '/' << c << "=" << endl;

                else if (f == 2)

                    cout << b << '/' << a << ' ' << '-' << ' ' << d << '/' << c << "=" << endl;

                else if (f == 3)

                    cout << b << '/' << a << ' ' << '*' << ' ' << d << '/' << c << "="  << endl;

                else

                    cout << b << '/' << a << ' ' << '/' << ' ' << d << '/' << c << "=" << endl;
            }
        
            else
            {
                if (f == 1)
                {
                    y = a + b;
                    cout << a << '+' << b << "=" << endl;
                }
                else if (f == 2)
                {
                    y = a - b;
                    cout << a << '-' << b << "=" << endl;
                }
                else if (f == 3)
                {
                    y = a * b;
                    cout << a << '*' << b << "=" <<  endl;
                }
                else
                {
                    y = b / a;
                    cout << b << '/' << a << "=" << endl;
                }
            }
        
        }
    }

    测试结果:

    感受:通过这次小测试,我明白了“分解”思想的重要性。

  • 相关阅读:
    搭建非域AlwaysOn win2016+SQL2016
    从0开始搭建SQL Server AlwaysOn 第四篇(配置异地机房节点)
    从0开始搭建SQL Server AlwaysOn 第二篇(配置故障转移集群)
    从0开始搭建SQL Server AlwaysOn 第三篇(配置AlwaysOn)
    从0开始搭建SQL Server AlwaysOn 第一篇(配置域控)
    四、基于Windows 2012配置SQL Server 2014 AlwaysOn
    三、安装SQLserver 2014(For AlwaysOn)
    二、 Windows 2012配置故障转移(For SQLServer 2014 AlwaysOn)
    Mybatis-SQL语句构建器类及日志
    Mybatis-JavaAPI
  • 原文地址:https://www.cnblogs.com/lvstudy/p/5248248.html
Copyright © 2011-2022 走看看