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

     #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");
     }
  • 相关阅读:
    Mvcpager以下各节已定义,但尚未为布局页“~/Views/Shared/_Layout.cshtml”呈现:“Scripts”。
    骆驼男鞋怎么样,骆驼男鞋售后逆天,骆驼男鞋维修36天无结果。程序员屌丝的维权之路,直播。。。。。。
    IOS7状态栏StatusBar官方标准适配方法
    iphone原生cookie处理
    拼接语句单引号里面如何用单引号
    判断Linux 系统负荷是否过载
    sys用户无法远程登陆
    ORA-12838: cannot read/modify an object after modifying it in parallel
    ORA-19504: failed to create file "/u01/backup/db_0_20190603_1" ORA-27038: created file already exists
    oracle中job无法正常运行,如何排查
  • 原文地址:https://www.cnblogs.com/ziteng1001/p/9752751.html
Copyright © 2011-2022 走看看