-
Notifications
You must be signed in to change notification settings - Fork 1
/
13_relation_testing_properties_and_equivalence.c
70 lines (69 loc) · 1.29 KB
/
13_relation_testing_properties_and_equivalence.c
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include<stdio.h>
#include<stdlib.h>
int main(){
int s[20],r[20][2],i,j,k,n,m,f=0,g=0,x,y,z=99;
printf("enter the no. of elements in a set:");
scanf("%d",&n);
printf("enter the elements of set:");
for(i=1;i<=n;i++)
scanf("%d",&s[i]);
printf("enter the no. of relation set:");
scanf("%d",&m);
printf("enter the pairs of relation set:");
for(i=1;i<=m;i++)
scanf("%d%d",&r[i][1],&r[i][2]);
printf("The entered relation is:");
printf("{");
for(i=1;i<=m;i++)
printf("(%d,%d),",r[i][1],r[i][2]);
printf("\b}");
f=0;
for(i=1;i<=m;i++){
if(r[i][1]==r[i][2])
f++;
}
if(f==n)
printf("\nThe enter set relation is refelexive.");
//to check either it is symmetric or not
f=0;g=0;
for(i=1;i<=m;i++){
x=r[i][1];
y=r[i][2];
g++;
for(j=1;j<=m;j++){
if(x==r[j][2]&&y==r[j][1])
f++;
}
if(f==0)
goto d;
f=0;
}
if(g==m)
printf("\nThe relation is symmetric.");
//to check either it is transitive or not
d:
f=0;g=0;
for(i=1;i<=m;i++){
for(j=1;j<=m;j++){
for(k=1;k<=m;k++){
x=r[i][1];
y=r[i][2];
if(y==r[j][1])
z=r[j][2];
if(x==r[k][1]&&z==r[k][2])
f++;
}}
if(f==0)
goto h;
f=0;
}
printf("\nThe relation is transitive.");
h:
f=0;
for(i=1;i<=m;i++){
if(r[i][1]>=r[i][2]&&r[i][2]>=r[i][1])
f++;
}
if(f==n)
printf("\n The relation is antisymmetric.");
}