#include<stdio.h>
#include<stdlib.h>
#include<time.h>
int main()
{
int a,b,c,i,d;
srand((time(NULL)));
for(i=0;i<20;i++)
{
a=rand()%100;
b=rand()%100;
c=rand()%4;
switch(c)
{
case 0:
printf("%d+%d=
",a,b);
printf("请输入正确答案:
");
int e;
scanf("%d",&e);
if(a+b==e)
printf("恭喜您回答正确!
");
else
printf("您回答错误,正确答案是%d
",a+b);
break;
case 1:
if(a<b)
{
d=a;
a=b;
b=d;
}
printf("%d-%d=
",a,b);
printf("请输入正确答案:
");
int f;
scanf("%d",&f);
if(a-b==f)
printf("恭喜您回答正确!
");
else
printf("您回答错误,正确答案是%d
",a-b);
break;
case 2:
printf("%d*%d=
",a,b);
printf("请输入正确答案:
");
int g;
scanf("%d",&g);
if(a*b==g)
printf("恭喜您回答正确!
");
else
printf("您回答错误,正确答案是%d
",a*b);
break;
case 3:
if(a*b==0)
{
a++;
b++;
if(a%b==0)
{
printf("%d/%d=
",a,b);
printf("请输入正确答案:
");
int h;
scanf("%d",&h);
if(a/b==h)
printf("恭喜您回答正确!
");
else
printf("您回答错误,正确答案是%d
",a/b);
break;
}
else
{
a++;
while(a%b!=0)
{
a++;
}
printf("%d/%d=
",a,b);
printf("请输入正确答案:
");
int j;
scanf("%d",&j);
if(a/b==j)
printf("恭喜您回答正确!
");
else
printf("您回答错误,正确答案是%d
",a/b);
}
}
else
{
if(a%b==0)
{
printf("%d/%d=
",a,b);
printf("请输入正确答案:
");
int i;
scanf("%d",&i);
if(a/b==i)
printf("恭喜您回答正确!
");
else
printf("您回答错误,正确答案是%d
",a/b);
break;
}
else
{
a++;
while(a%b!=0)
{
a++;
}
printf("%d/%d=
",a,b);
printf("请输入正确答案:
");
int k;
scanf("%d",&k);
if(a/b==k)
printf("恭喜您回答正确!
");
else
printf("您回答错误,正确答案是%d
",a/b);
}
}
}
}
return 0;
}