#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#define N 10
void main()
{
int i,right=0,error=0;
int x,y,op,result,input;
char ops;
srand(time(NULL));
printf("请计算下列二元算术表达式的结果:\n");
for(i=1;i<=N;i++)
{
printf("第%-2d题:",i);
x=rand()%100;
y=rand()%100;
op=rand()%4;
switch(op)
{ /*根据不同的运算符计算二元算术表达式*/
case 0:result=x+y;
ops='+';
break;
case 1:result=x-y;
ops='-';
break;
case 2:result=x*y;
ops='*';
break;
case3:result=x/y;
ops=’/’;
break;
default:break;
}
printf("%d%c%d=",x,ops,y);
scanf("%d",&input);
if(result==input) /*判断用户计算是否准确*/
{
printf("正确!\n");
right=right+1;
}
else
{
printf("错误!\n");
error=error+1;
}
}
printf("你做对了%d道题,做错了%d道题。\n",right,error);
getchar();
}
#include<stdlib.h>
#include<time.h>
#define N 10
void main()
{
int i,right=0,error=0;
int x,y,op,result,input;
char ops;
srand(time(NULL));
printf("请计算下列二元算术表达式的结果:\n");
for(i=1;i<=N;i++)
{
printf("第%-2d题:",i);
x=rand()%100;
y=rand()%100;
op=rand()%4;
switch(op)
{ /*根据不同的运算符计算二元算术表达式*/
case 0:result=x+y;
ops='+';
break;
case 1:result=x-y;
ops='-';
break;
case 2:result=x*y;
ops='*';
break;
case3:result=x/y;
ops=’/’;
break;
default:break;
}
printf("%d%c%d=",x,ops,y);
scanf("%d",&input);
if(result==input) /*判断用户计算是否准确*/
{
printf("正确!\n");
right=right+1;
}
else
{
printf("错误!\n");
error=error+1;
}
}
printf("你做对了%d道题,做错了%d道题。\n",right,error);
getchar();
}