预计花费时间40分钟
实际花费时间35分钟
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define N 10
int Test()
{
int num = 0;
int answer = 0;
int result = 0;
int m = 0;
int n = 0;
char op = 0;
int count = N;
while ( count-- )
{
m = rand() % 10;
n = rand() % 10;
op = rand() % 4;
switch ( op )
{
case 0:
op = '+';
answer = m+n;
break;
case 1:
op = '-';
answer = m-n;
break;
case 2:
op = '*';
answer = m*n;
break;
case 3:
n++;
op = '/';
answer = m/n;
break;
default:
break;
}
printf("
题目:");
printf("%d%c%d=?
", m, op, n);
printf("请输入答案:");
scanf("%d", &result);
if ( answer == result )
num++;
}
return num;
}
int main()
{
srand( time(NULL) );
printf("开始做题:
");
printf("答题结束,你总共答对%d道题目。
", Test());
return 0;
}