zoukankan      html  css  js  c++  java
  • 30道四则运算

    一、题目要求

         二柱一下打印出好多份不同的题目,让孩子做了。老师看了作业之后,对二柱赞许有加。别的老师闻讯, 问二柱能否扩大他的影响力,编个软件,给二年级到四年级都用,多了一些小小的要求:

     1、题目避免重复;
    2、可定制(数量/打印方式);
    3、可以控制下列参数: 是否有乘除法、是否有括号、 数值范围、加减有无负数、除法有无余数、否支持分数 (真分数, 假分数, …)、是否支持小数 (精确到多少位)、打印中每行的间隔可调整;

    二、设计思想:

    先不管别的,把30道四则运算题目输出来是前提,这是第一步分解题目;

    三、代码:

    两种方法,第一种方法:

    #include <iostream.h>
    #include <stdlib.h>
    int main()
    {
    	int a,b,c;
    	for(int i=0;i<30;i++)
    	{
    		a=rand()%100;//x+rand()%(y-x+1)随机生成【x,y】内的整数
    		b=rand()%100;
    		c=rand()%4;
    		switch (c)
    		{
    			case 1:
    			cout<<a<<"+"<<b<<"="<<endl;
    			break;
    			case 2:	
    			cout<<a<<"-"<<b<<"="<<endl;
    			break;
    			case 3:	
    			cout<<a<<"*"<<b<<"="<<endl;
    			break;
    			case 4:	
    			cout<<a<<"/"<<b<<"="<<endl;
    			break;	
    		}	
    	}
    	return 0;
    }
    

      

    第二种方法不用脑子:

    #include <iostream.h>
    #include <stdlib.h>
    int main()
    {
        cout<< "1. 3/7 × 49/9 - 4/3 "<<endl;
        cout<< "2. 8/9 × 15/36 + 1/27 "<<endl;
        cout<< "3. 12× 5/6 – 2/9 ×3 "<<endl;
        cout<< "4. 8× 5/4 + 1/4 "<<endl;
        cout<< "5. 6÷ 3/8 – 3/8 ÷6 "<<endl
        << "6. 4/7 × 5/9 + 3/7 × 5/9 "<<endl
        << "7. 5/2 -( 3/2 + 4/5 ) "<<endl
        << "8. 7/8 + ( 1/8 + 1/9 ) "<<endl
        << "9. 9 × 5/6 + 5/6 "<<endl
        << "10. 3/4 × 8/9 - 1/3 "<<endl
        << "11. 7 × 5/49 + 3/14 "<<endl
        << "12. 6 ×( 1/2 + 2/3 ) "<<endl
        << "13. 8 × 4/5 + 8 × 11/5 "<<endl
        << "14. 31 × 5/6 – 5/6 "<<endl
        << "15. 9/7 - ( 2/7 – 10/21 ) "<<endl
        << "16. 5/9 × 18 – 14 × 2/7 "<<endl
        << "17. 4/5 × 25/16 + 2/3 × 3/4 "<<endl
        << "18. 14 × 8/7 – 5/6 × 12/15 "<<endl
        << "19. 17/32 – 3/4 × 9/24 "<<endl
        << "20. 3 × 2/9 + 1/3 "<<endl
        << "21. 5/7 × 3/25 + 3/7 "<<endl
        << "22. 3/14 ×× 2/3 + 1/6 "<<endl
        << "23. 1/5 × 2/3 + 5/6 "<<endl
        << "24. 9/22 + 1/11 ÷ 1/2 "<<endl
        << "25. 5/3 × 11/5 + 4/3 "<<endl
        << "26. 45 × 2/3 + 1/3 × 15 "<<endl
        << "27. 7/19 + 12/19 × 5/6 "<<endl
        << "28. 1/4 + 3/4 ÷ 2/3 "<<endl
        << "29. 8/7 × 21/16 + 1/2 "<<endl
        << "30. 101 × 1/5 – 1/5 × 21"<<endl;
    
        return 0;
    }

    四、总结

      这道题目如果开始没有思路,就用上面的第二种没脑子的方法,不管别的我就是能给出你结果才是正确的;因为做的设计题目有限,没有能够熟练快速的写出来。以后要加强锻炼;每天在晚上的时候做一些基础的练习,以为万丈高楼平地起,基础打得牢,才能走的更远。

  • 相关阅读:
    ActiveMQ 即时通讯服务 浅析
    Asp.net Mvc (Filter及其执行顺序)
    ActiveMQ基本介绍
    ActiveMQ持久化消息的三种方式
    Windows Azure Virtual Machine (27) 使用psping工具,测试Azure VM网络连通性
    Azure China (10) 使用Azure China SAS Token
    Windows Azure Affinity Groups (3) 修改虚拟网络地缘组(Affinity Group)的配置
    Windows Azure Storage (22) Azure Storage如何支持多级目录
    Windows Azure Virtual Machine (26) 使用高级存储(SSD)和DS系列VM
    Azure Redis Cache (2) 创建和使用Azure Redis Cache
  • 原文地址:https://www.cnblogs.com/zhaixing/p/4317950.html
Copyright © 2011-2022 走看看