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");
    }

  • 相关阅读:
    Java 字符串总结
    782B The Meeting Place Cannot Be Changed(二分)
    初学hash
    Codeforces Round #395 C. Timofey and a tree
    Java集合之ArrayList
    CA Loves GCD (BC#78 1002) (hdu 5656)
    hdu 5661 Claris and XOR
    hdu 5945 Fxx and game
    pay包注释(二)
    编程风格
  • 原文地址:https://www.cnblogs.com/w-t-c/p/9755086.html
Copyright © 2011-2022 走看看