Home > Article > Backend Development > 201306114357-Experiment 1, 201306114357-Experiment_PHP Tutorial
#include
#include
#include
main()
{
int a,b,c;
float resultTrue=0,n;
char op;
srand(time(NULL));
do
{
a=rand() 1;
b=rand() 1;
c=rand()%4 1;
switch(c%4)
{
case 0:
{
op=' ';
break;
}
case 1:
{
op='-';
break;
}
case 2:
{
op='*';
break;
}
case 3:
{
op='/';
break;
}
}
printf("%d%c%d=n",a,op,b);
switch(op)
{
case ' ':
{
resultTrue=a b;
break;
}
case '-':
{
resultTrue=a-b;
break;
}
case '*':
{
resultTrue=a*b;
break;
}
case '/':
{
resultTrue=a/b;
break;
}
}
printf("请输入正确答案(1000为结束):");
scanf("%f",&n);
if(n!=0)
{
if(resultTrue!=n)
{
printf("答案错误,答案为%dn",resultTrue);
}
if(resultTrue==n)
{
printf("答案正确n");
}
}
if(n==10000)
{
return;
}
}while(1);
}