二柱子的出題軟體

來源:互聯網
上載者:User

標籤:bsp   turn   oat   main   沒有想到   實現   ima   cat   sys   

二柱子的軟體

支援真分數的四則運算

可定義出題數量

#define _CRT_SECURE_NO_DEPRECATE
#include<stdio.h>
#include<Windows.h>
#include<time.h>
int main()
{
 int a, b, c, d, e, f, g, k;
 float p, q;
 printf("請輸入想要の數量");
 scanf("%d",&k);
 srand(unsigned(time(NULL)));
 for (e = 0; e < k; e++)
 {
  a = rand() % 100;
  b = rand() % 100;
  c = rand() % 5;
  switch (c)
  {
  case 0: printf("第%d題:%d + %d =\n",e+1, a, b);
   break;
  case 1:if (a < b)
  {
   d = a;
   a = b;
   b = d;
  }
      printf("第%d題:%d - %d =\n",e+1, a, b);
      break;
  case 2:printf("第%d題:%d * %d =\n",e+1, a, b);
   break;
  case 3:
   while (b == 0)
   {
    b = rand() % 100;
   }
   printf("第%d題:%d / %d =\n",e+1, a, b);
   break;
  case 4:
   a = rand() % 100;
   b = rand() % 100;
   f = rand() % 100;
   g = rand() % 100;
   c = rand() % 4;
   while (b == 0)
   {
    b = rand() % 100;
   }
   while (g == 0)
   {
    g = rand() % 100;
   }
   if (a > b)
   {
    d = a;
    a = b;
    b = d;
   }
   if (f > g)
   {
    d = f;
    f = g;
    g = d;
   }
   switch (c)
   {
   case 0:printf("第%d題:%d/%d + %d/%d =\n",e+1, a, b, f, g);
    break;
   case 1:
    p = (float)a / (float)b;
    q = (float)f / (float)g;
    if (p < q)
    {
     d = a;
     a = f;
     f = d;
     d = b;
     b = g;
     g = d;
    }
    printf("第%d題:%d/%d - %d/%d =\n",e+1, a, b, f, g);
    break;
   case 2:printf("第%d題:%d/%d * %d/%d =\n",e+1, a, b, f, g);
    break;
   case 3:
    a = rand() % 100;
    b = rand() % 100;
    f = rand() % 100;
    g = rand() % 100;
    c = rand() % 4;
    while (f == 0)
    {
     f = rand() % 100;
    }
    printf("第%d題:%d/%d / %d/%d =\n",e+1, a, b, f, g);
    break;
   }
  }
 }
 system("pause");
 return 0;
}

總結:雖然通過運用C語言實現了這個小程式大部分要求,但是還是沒有想到避免重複的方法。

二柱子的出題軟體

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.