C语言编程 设计一个100以内的整数四则运算测试程序
(1)Givetheoptionmenutointegratevariousfunctionmodule.选项菜单集成各功能函数模块(2)Setsthetopicofac...
(1) Give the option menu to integrate variousfunction module.选项菜单集成各功能函数模块
(2) Sets the topic of a composition (each timesets 5 topics).出题(每次出10道题目)
(3) Answer and grade.答题并评分
(4) Give the correct answer to the wrong topic.答错的题给出正确答案
(5) Demonstrating the answer paper显示答卷 展开
(2) Sets the topic of a composition (each timesets 5 topics).出题(每次出10道题目)
(3) Answer and grade.答题并评分
(4) Give the correct answer to the wrong topic.答错的题给出正确答案
(5) Demonstrating the answer paper显示答卷 展开
1个回答
展开全部
#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;
}
追问
能不能备注一下具体步骤内容 每个点在什么地方
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |