求大神编一个C语言的题———[题目描述]随机产生1-10之间的随机正整数,进行四则运算,共十道题,
#include "stdio.h"
#include "stdlib.h"
#include "time.h"
int main()
{
int i,j,a,b,c,ans,ans1,score=0;
float ans2;
for(i=0;i<10;i++)
{
srand(time(0));
a=rand()%9+1;
b=rand()%9+1;
c=rand()%3;
switch(c)
{
case 0:
ans=a+b;
printf("%d+%d=?\n",a,b);
scanf("%d",&ans1);
for(j=0;j<2;j++)
{
if(ans1==ans)
{
score+=10;
printf("Good!\n");
break;
}
else
{
printf("Wrong,Try Again!\n");
scanf("%d",&ans1);
}
}
break;
case 1:
ans=a-b;
printf("%d-%d=?\n",a,b);
scanf("%d",&ans1);
for(j=0;j<2;j++)
{
if(ans1==ans)
{
score+=10;
printf("Good!\n");
break;
}
else
{
printf("Wrong,Try Again!\n");
scanf("%d",&ans1);
}
}
break;
case 2:
ans=a*b;
printf("%d*%d=?\n",a,b);
scanf("%d",&ans1);
for(j=0;j<2;j++)
{
if(ans1==ans)
{
score+=10;
printf("Good!\n");
break;
}
else
{
printf("Wrong,Try Again!\n");
scanf("%d",&ans1);
}
}
break;
case 3:
ans2=(float)a/b;
printf("%d/%d=?\n",a,b);
scanf("%d",&ans1);
for(j=0;j<2;j++)
{
if(ans1==ans2)
{
score+=10;
printf("Good!\n");
break;
}
else
{
printf("Wrong,Try Again!\n");
scanf("%d",&ans1);
}
}
break;
}
}
printf("您的成绩是:%d\n",score);
return 0;
}
运行结果: