二柱子的出题软件

二柱子的软件

支持真分数的四则运算

可定义出题数量

#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 = ",e+1, a, b);
   break;
  case 1:if (a < b)
  {
   d = a;
   a = b;
   b = d;
  }
      printf("第%d题:%d - %d = ",e+1, a, b);
      break;
  case 2:printf("第%d题:%d * %d = ",e+1, a, b);
   break;
  case 3:
   while (b == 0)
   {
    b = rand() % 100;
   }
   printf("第%d题:%d / %d = ",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 = ",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 = ",e+1, a, b, f, g);
    break;
   case 2:printf("第%d题:%d/%d * %d/%d = ",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 = ",e+1, a, b, f, g);
    break;
   }
  }
 }
 system("pause");
 return 0;
}

总结:虽然通过运用C语言实现了这个小程序大部分要求,但是还是没有想到避免重复的方法。

原文地址:https://www.cnblogs.com/nanzhujue/p/9751865.html