二柱子的出題軟件
二柱子的軟件
支持真分數的四則運算
可定義出題數量
#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語言實現了這個小程序大部分要求,但是還是沒有想到避免重復的方法。
二柱子的出題軟件