发布网友 发布时间:2024-10-03 10:13
共2个回答
热心网友 时间:21小时前
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
const int MAXSIZE = 10;
int CheckResult(int anwser,int result) {
if(anwser == result) {
printf("对的,继续努力\n");
return 1;
}
printf("错了,正确答案是:%d\n",result);
return 0;
}
int main() {
int a,b,t,answer,result;
int n = MAXSIZE,yes = 0,no = 0;
char op,ops[] = {"+-*/"};
srand((unsigned)time(NULL));
while(n--) {
op = rand()%4;
switch(ops[op]) {
case '+' : do {
a = rand()%90 + 10;
b = rand()%90 + 10;
}while(a + b >= 100);
printf("%d + %d = ",a,b);
scanf("%d",&answer);
if(CheckResult(answer,a + b)) ++yes;
else ++no;
break;
case '-' : a = rand()%90 + 10;
b = rand()%90 + 10;
if(a < b) {t = a; a = b; b = t; }
printf("%d - %d = ",a,b);
scanf("%d",&answer);
if(CheckResult(answer,a - b)) ++yes;
else ++no;
break;
case '*' : do {
a = rand()%100;
b = rand()%100;
}while(a * b >= 100);
printf("%d * %d = ",a,b);
scanf("%d",&answer);
if(CheckResult(answer,a * b)) ++yes;
else ++no;
break;
case '/' : do {
a = rand()%90 + 1;
b = rand()%90 + 1;
}while(a % b && b % a);
if(a % b) {t = a; a = b; b = t; }
printf("%d / %d = ",a,b);
scanf("%d",&answer);
if(CheckResult(answer,a / b)) ++yes;
else ++no;
break;
}
}
printf("答对:%d个,答错:%d个,正确率:%.2lf%%\n",yes,no,100.0 * yes / MAXSIZE);
return 0;
}
热心网友 时间:21小时前
太难了