...c语言 B-8.100以内的整数四则运算测试程序设计 (1)选项菜单集成各...

发布网友 发布时间: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小时前

太难了

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com