zoukankan      html  css  js  c++  java
  • 软件工程课后作业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 = ", a, b);
                 break;
             case 1:if (a < b)
             {
                        d = a;
                        a = b;
                        b = d;
             }
                    printf("%d - %d = ", a, b);
                    break;
             case 2:printf("%d * %d = ", a, b);
                 break;
             case 3:
                while (b == 0)
                 {
                     b = rand() % 100;
                 }
                 printf("%d / %d = ", 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 = ", 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 = ", a,b,m,n);
                     break;
                 case 2:printf("%d/%d * %d/%d = ", 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 = ", a, b, m, n);
                     break;
                 }
             }
         }
         system("pause");
     }言:

    运行结果:

  • 相关阅读:
    Eclipse的Tomcat插件安装
    Struts1.2 struts-config.xml配置详解
    JavaWeb:报错信息The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path
    dede 忘记密码在数据库中修改方法
    如何将XML文件中的数据传送并保存在关系数据库中
    lamp
    开发人员必读的11本最具影响力书籍
    org.apache.commons.lang.StringUtils类
    B. Jzzhu and Sequences
    线段树——习题、lazy解析
  • 原文地址:https://www.cnblogs.com/haodong9/p/9751980.html
Copyright © 2011-2022 走看看