#include<stdio.h>
2 #include<Windows.h>
3 #include<time.h>
4 void main()
5 {
6 int a, b, c, d,i,m,n;
7 float p, q;
8 srand(unsigned( time(NULL)));
9 for (i = 0; i < 30; i++)
10 {
11 a = rand() % 100;
12 b = rand() % 100;
13 c = rand() % 5;
14 switch (c)
15 {
16 case 0: printf("%d + %d =\\n", a, b);
17 break;
18 case 1:if (a < b)
19 {
20 d = a;
21 a = b;
22 b = d;
23 }
24 printf("%d - %d =\\n", a, b);
25 break;
26 case 2:printf("%d * %d =\\n", a, b);
27 break;
28 case 3:
29 while (b == 0)
30 {
31 b = rand() % 100;
32 }
33 printf("%d / %d =\\n", a, b);
34 break;
35 case 4:
36 a = rand() % 100;
37 b = rand() % 100;
38 m = rand() % 100;
39 n = rand() % 100;
40 c = rand() %4 ;
41 while (b == 0)
42 {
43 b = rand() % 100;
44 }
45 while (n == 0)
46 {
47 n = rand() % 100;
48 }
49 if (a > b)
50 {
51 d = a;
52 a = b;
53 b = d;
54 }
55 if (m > n)
56 {
57 d = m;
58 m = n;
59 n = d;
60 }
61 switch (c)
62 {
63 case 0:printf("%d/%d + %d/%d =\\n", a, b, m, n);
64 break;
65 case 1:
66 p = (float)a / (float)b;
67 q = (float)m / (float)n;
68 if (p < q)
69 {
70 d = a;
71 a = m;
72 m = d;
73 d = b;
74 b = n;
75 n = d;
76 }
77 printf("%d/%d - %d/%d =\\n", a,b,m,n);
78 break;
79 case 2:printf("%d/%d * %d/%d =\\n", a, b, m, n);
80 break;
81 case 3:
82 a = rand() % 100;
83 b = rand() % 100;
84 m = rand() % 100;
85 n = rand() % 100;
86 c = rand() % 4;
87 while (m == 0)
88 {
89 m = rand() % 100;
90 }
91 printf("%d/%d / %d/%d =\\n", a, b, m, n);
92 break;
93 }
94 }
95 }
96 system("pause");
97 }