Determine if a relation is reflexive

Hello all, I am working on a program that will look at a relation and determine if it is reflexive or not. So far I am able to go through the pairs and determine if they are equal or not. I cannot figure out a way for the program to determine if the relation is reflexive. I would assume if for a number it does not find a pair then the function should return false. I cannot figure out how to code for this. Any tips would be greatly appreciated. ar1 is the first numbers in each par and ar2 is the seconds numbers.

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
  #include <iostream>
using namespace std;
bool isreflexive(int ar[],int n,int ar2[],int nn)
{
int j,i = 0;

cout<<"n " <<n<<endl;
for(i = 0; i <n-1; i++)
   {
    cout<<"i "<<i<<endl;
    if(ar[i] == ar2[j])
    {
      cout<<"match"<<endl;
     j++;
    }
   else
   {
     cout<<"not a match"<<endl;
     j++;
   }
}


}


int main()
{

int  ar[] = {1,2,3,4,4,7,7 };
int ar2[] = {1,2,3,4,7,4,7};
int n = sizeof(ar)/sizeof(int);
int nn = sizeof(ar2)/sizeof(int);
cout<<n<<endl;


if( isreflexive(ar,n, ar2,nn))
   {
      cout<<"is reflexive"<<endl;
    }
    else
    {
       cout<<"is not reflexive"<<endl;
    }
}
Last edited on
Topic archived. No new replies allowed.