四则运算
#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=\n",a,b);
printf("请输入正确答案:\n");
int e;
scanf("%d",&e);
if(a+b==e)
printf("恭喜您回答正确!\n");
else
printf("您回答错误,正确答案是%d\n",a+b);
break;
case 1:
if(a<b)
{
d=a;
a=b;
b=d;
}
printf("%d-%d=\n",a,b);
printf("请输入正确答案:\n");
int f;
scanf("%d",&f);
if(a-b==f)
printf("恭喜您回答正确!\n");
else
printf("您回答错误,正确答案是%d\n",a-b);
break;
case 2:
printf("%d*%d=\n",a,b);
printf("请输入正确答案:\n");
int g;
scanf("%d",&g);
if(a*b==g)
printf("恭喜您回答正确!\n");
else
printf("您回答错误,正确答案是%d\n",a*b);
break;
case 3:
if(a*b==0)
{
a++;
b++;
if(a%b==0)
{
printf("%d/%d=\n",a,b);
printf("请输入正确答案:\n");
int h;
scanf("%d",&h);
if(a/b==h)
printf("恭喜您回答正确!\n");
else
printf("您回答错误,正确答案是%d\n",a/b);
break;
}
else
{
a++;
while(a%b!=0)
{
a++;
}
printf("%d/%d=\n",a,b);
printf("请输入正确答案:\n");
int j;
scanf("%d",&j);
if(a/b==j)
printf("恭喜您回答正确!\n");
else
printf("您回答错误,正确答案是%d\n",a/b);
}
}
else
{
if(a%b==0)
{
printf("%d/%d=\n",a,b);
printf("请输入正确答案:\n");
int i;
scanf("%d",&i);
if(a/b==i)
printf("恭喜您回答正确!\n");
else
printf("您回答错误,正确答案是%d\n",a/b);
break;
}
else
{
a++;
while(a%b!=0)
{
a++;
}
printf("%d/%d=\n",a,b);
printf("请输入正确答案:\n");
int k;
scanf("%d",&k);
if(a/b==k)
printf("恭喜您回答正确!\n");
else
printf("您回答错误,正确答案是%d\n",a/b);
}
}
}
}
return 0;
}