十以内加减乘除练习辅助系统
时间: 2023-07-26 21:14:10 浏览: 73
好的,以下是一个十以内加减乘除练习辅助系统的 C 代码示例:
```c
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main() {
int num1, num2, answer, result;
char operator;
int correct_count = 0, wrong_count = 0;
printf("欢迎使用十以内加减乘除练习辅助系统!\n");
printf("您将需要回答20道十以内加减乘除的算术题目,系统会自动统计您的得分。\n");
srand((unsigned int) time(NULL)); // 随机数生成器初始化
for (int i = 1; i <= 20; i++) {
num1 = rand() % 10;
num2 = rand() % 10;
operator = rand() % 4; // 0代表加法,1代表减法,2代表乘法,3代表除法
switch (operator) {
case 0:
answer = num1 + num2;
printf("%d + %d = ", num1, num2);
break;
case 1:
answer = num1 - num2;
printf("%d - %d = ", num1, num2);
break;
case 2:
answer = num1 * num2;
printf("%d × %d = ", num1, num2);
break;
case 3:
answer = num1 / num2;
printf("%d ÷ %d = ", num1, num2);
break;
}
scanf("%d", &result);
if (result == answer) {
printf("√\n");
correct_count++;
} else {
printf("×,正确答案是 %d\n", answer);
wrong_count++;
}
}
printf("答题完毕!您总共回答了20道题目,其中正确的有%d道,错误的有%d道。\n", correct_count, wrong_count);
return 0;
}
```
这段代码会生成20道随机的十以内加减乘除算术题目,并让用户输入答案。用户回答完毕后,系统会自动统计正确和错误的题目数量,并输出最终得分。请注意,这个练习辅助系统只支持十以内的加减乘除运算,且除法运算只能得到整数结果。
阅读全文