#include #include #include #definen 10 int i right=0. error=0 int x, y, op, result, input srand(time(NULL)) printf("请计算下列二元算术表达式的结果n") for(i=l K<=N; i++) printi("第%-2d题:",); rand%100 y=rando%100 switch(op) *根据不同的运算符计算二元算术表达式* case O: result=x+y case 1: result=x-y break case 2: result=x*y default: break printf("%d%c%d="x, ops, y); scanf("%d", &input) if(result==input) /*判断用户计算是否准确* printi("正确!hn") printi("错误!n") error=error+I
#include #include #include #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("你做对了%ad道题,做错了%d道题。mn",rght;emor) getchar:
} } printf("你做对了%d 道题,做错了%d 道题。\n",right,error); getchar(); }