具体代码如下
1 #include
2 using namespace std;
3
4 void Input(int a[25][2],int s)
5 {
6 int i;
7
8 for (i = 0; i )
9 {
10 cin >> a[i][0] >> a[i][1];
11 }
12 }
13
14 void Output(int a[5][2],int b[5][5], int n,int s)
15 {
16 int i;
17 int j, k;
18 int buff=0;
19 int buff1, buff2;
20 cout <
21 for (i &#61; 0; i )
22 {
23 buff1 &#61; a[i][0] - 1;
24 buff2 &#61; a[i][1] - 1;
25 b[buff1][buff2] &#61; 1;
26 }
27 for (j &#61; 0; j
28 {
29 for (k &#61; 0; k
30 {
31 cout <" ";
32 buff&#43;&#43;;
33 if (buff%n &#61;&#61; 0)
34 cout << endl;
35 }
36 }
37 cout << endl;
38 }
39 void IsReflexive(int b[5][5],int n)
40 {
41 int i;
42 cout <<"1、Is Reflexive?" <
43 for (i &#61; 0; i
44 {
45 if (!b[i][i])
46 {
47 cout <<"the answer is NO!" << endl;
48 cout <<"At least can&#39;t find" <<"<" <1 <<"," <1 <<">" <
49 return;
50 }
51 }
52 cout <<"the answer is YES!" <
53 }
54 void IsAntireflexive(int b[5][5], int n)
55 {
56 int i;
57 cout <<"2、Is Antireflexive?" <
58 for (i &#61; 0; i
59 {
60 if (b[i][i])
61 {
62
63 cout <<"the answer is NO!" << endl;
64 cout <<"At least find" <<"<" <1 <<"," <1 <<">" <
65 return;
66 }
67 }
68 cout <<"the answer is YES!" <
69 }
70 void IsSymmetric(int b[5][5], int n)
71 {
72 int i, j;
73 cout <<"3、Is Symmetric?" <
74 for (i &#61; 0; i
75 {
76 for (j &#61; 0; j
77 {
78 if (b[i][j] !&#61; b[j][i])
79 {
80 cout <<"the answer is NO!" << endl;
81 cout <<"At least both of" <<"<" <1 <<"," <
82 return;
83 }
84 }
85
86 }
87 cout <<"the answer is YES!" <
88 }
89 void IsAntisymmetry(int b[5][5], int n)
90 {
91 int i, j;
92 cout <<"4、Is Antisymmetry?" <
93 for (i &#61; 0; i
94 {
95 for (j &#61; 0; j
96 {
97 if (b[i][j] && b[i][j] &#61;&#61; b[j][i] && i !&#61; j)
98 {
99 cout <<"the answer is NO!" << endl;
100 cout <<"At least both of" <<"<" <1 <<"," <
101 return;
102 }
103 }
104 }
105 cout <<"the answer is YES!" <
106 }
107 void IsTransmit(int b[5][5], int n)
108 {
109 int i, j, k;
110 cout <<"5、Is Transmit?" <
111 for (i &#61; 0; i
112 {
113 for (j &#61; 0; j
114 {
115 for (k &#61; 0; k
116 {
117 if (b[i][j] && b[j][k]&&!b[i][k])
118 {
119
120 cout <<"the answer is NO!" << endl;
121 cout <<"At lease can&#39;t find" <<"<" <1 <<"," <
122 return;
123
124 }
125
126 }
127 }
128 }
129 cout <<"the answer is YES!" <
130 }
131 int main()
132 {
133 int In[25][2];
134 int Pu[5][5] &#61; {0};
135 int n ;
136
137 cout <<"input number of the element(0<&#61;n<&#61;5)" <
138
139 cin >> n;
140 for (int l &#61; 0; l
141 {
142 cout <
143
144 }
145 cout << endl;
146 while (n <0||n>5)
147 {
148 cout <<"error!" << endl;
149 cin >> n;
150 }
151 int s;
152 cout <<"input a number of relation" <
153 cin >> s;
154 cout <<"input the relation" << endl;
155 Input(In, s);
156 Output(In,Pu, n,s);
157 IsReflexive(Pu, n);
158 IsAntireflexive(Pu,n);
159 IsSymmetric(Pu, n);
160 IsAntisymmetry(Pu, n);
161 IsTransmit(Pu, n);
162 system("pause");
163 return 0;
164
165 }