1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
void get_mondai(char *ope, int *ope1, int *ope2, int *ans) {
char ope_list[] = { '+', '-', '*', '/' };
*ope = ope_list[rand() % 4];
*ope1 = rand() % 9 + 1;
*ope2 = rand() % 9 + 1;
switch (*ope) {
case '+': *ans = *ope1 + *ope2; break;
case '-': *ans = *ope1 - *ope2; break;
case '*': *ans = *ope1 * *ope2; break;
case '/': *ans = *ope1; *ope1 *= *ope2; break;
}
}
void main() {
char ope;
int ope1, ope2, ans, val;
int i;
srand((unsigned)time(NULL));
for (i = 0; i < 5; i++) {
get_mondai(&ope, &ope1, &ope2, &ans);
printf("%d %c %d = ", ope1, ope, ope2);
scanf("%d", &val);
printf("%s\n", (val == ans) ? "atari" : "hazure");
}
}