程序源代码
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(void)
{
int i = 0;
int e,f,g,h,x1,x2,y,z;//g为计算值
srand((unsigned)time(NULL)); //本地时间为种子
printf("请选择你需要的题目类型
整数运算请输入1 真分数运算请输入2
");
scanf("%d", &x1);
printf("请输入出题数量
");
scanf("%d", &x2);
switch (x1)
{
case 1:
{
while (i < x2)
{
int a = rand() % 100; //产生随机数
int b = rand() % 100;
int j;
j = rand() % 4; //产生随机符号0到3分别代表四则运算
printf("%d", a);
switch (j)
{
case 0:
printf("+");
g=a+b;
break;
case 1:
printf("-");
g=a-b;
break;
case 2:
printf("*");
g=a*b;
break;
case 3:
printf("/");
g=a/b;
break;
}
printf("%d", b);
printf(" = ");
scanf("%d",&z);
if(g==z)
printf("回答正确
");
else if(g!=z)
printf("回答错误
");
i++;
}
}
case 2:
{
while (i < x2)
{
int a = rand() % 100; //产生随机数
int b = rand() % 100;
int c = rand() % 100;
int d = rand() % 100;
int j = rand() % 4; //产生随机符号0到3分别代表四则运算
if (b != 0 && d != 0)
{
if (a > b)
{
e = a, a = b, b = e;
}
if (c > d)
{
f = c, c = d, d = f;
}
printf("%d/%d", a, b);
switch (j)
{
case 0:
printf("+");
break;
case 1:
printf("-");
break;
case 2:
printf("*");
break;
case 3:
printf("/");
break;
}
printf("%d/%d", c, d);
printf("=");
scanf("%d/%d",&y,&z);
if(g==y/z)
printf("回答正确
");
else if(g!=y/z)
printf("回答错误
");
i++;
}
}
}
}
getchar();
getchar();
return 0;
}
整个程序还有一些不健全的地方,还需后期继续完善。