博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
二年级四则运算扩展,可以指定题目数量,并可支持真分数运算
阅读量:5173 次
发布时间:2019-06-13

本文共 1295 字,大约阅读时间需要 4 分钟。

多出来的要求:

1.可以指定题目数量:

2.支持真分数运算

实现代码:

 

#include<stdio.h>

  #include<Windows.h>
  #include<time.h>
  void main()
  {
      int a, b, c, d,i,m,n;
      float p, q;
      srand(unsigned( time(NULL)));
      for (i = 0; i < 30; i++)
  
   {
         a = rand() % 100;
         b = rand() % 100;
         c = rand() % 5;
         switch (c)
         {
        case 0: printf("%d + %d =\n", a, b);
             break;
         case 1:if (a < b)
         {
                    d = a;
                    a = b;
                    b = d;
         }
                printf("%d - %d =\n", a, b);
                break;
         case 2:printf("%d * %d =\n", a, b);
             break;
         case 3:
            while (b == 0)
             {
                 b = rand() % 100;
             }
             printf("%d / %d =\n", a, b);
             break;
         case 4:
             a = rand() % 100;
             b = rand() % 100;
             m = rand() % 100;
             n = rand() % 100;
             c = rand() %4 ;
             while (b == 0)
             {
                 b = rand() % 100;
             }
             while (n == 0)
             {
                 n = rand() % 100;
             }
             if (a > b)
             {
                 d = a;
                 a = b;
                 b = d;
             }
             if (m > n)
             {
                 d = m;
                 m = n;
                 n = d;
            }
             switch (c)
             {
             case 0:printf("%d/%d + %d/%d =\n", a, b, m, n);
                 break;
             case 1:
                 p = (float)a / (float)b;
                 q = (float)m / (float)n;
                 if (p < q)
                 {
                     d = a;
                     a = m;
                     m = d;
                     d = b;
                     b = n;
                     n = d;
                 }
                printf("%d/%d - %d/%d =\n", a,b,m,n);
                 break;
             case 2:printf("%d/%d * %d/%d =\n", a, b, m, n);
                 break;
             case 3:
                 a = rand() % 100;
                 b = rand() % 100;
                 m = rand() % 100;
                 n = rand() % 100;
                 c = rand() % 4;
                 while (m == 0)
                 {
                     m = rand() % 100;
                }
                 printf("%d/%d / %d/%d =\n", a, b, m, n);
                 break;
             }
         }
     }
     system("pause");
 }

 

运行结果:

 

 

转载于:https://www.cnblogs.com/IENHOLT/p/9751749.html

你可能感兴趣的文章
201421410014蒋佳奇
查看>>
Xcode5和ObjC新特性
查看>>
CSS属性值currentColor
查看>>
Real-Time Rendering 笔记
查看>>
多路复用
查看>>
【UVA】434-Matty&#39;s Blocks
查看>>
hadoop2.2.0+hive-0.10.0完全分布式安装方法
查看>>
使用Reporting Services时遇到的小问题
查看>>
约瑟夫问题
查看>>
Arduino 报错总结
查看>>
树莓派Android Things物联网开发:树莓派GPIO引脚图
查看>>
矩阵快速幂---BestCoder Round#8 1002
查看>>
Hadoop HBase概念学习系列之HBase里的宽表设计概念(表设计)(二十七)
查看>>
awk变量
查看>>
mysql_对于DQL 的简单举例
查看>>
35. Search Insert Position(C++)
查看>>
[毕业生的商业软件开发之路]C#异常处理
查看>>
有关快速幂取模
查看>>
NOI2018垫底记
查看>>
注意java的对象引用
查看>>