Write a computer program to find the number of transitive re
Write a computer program to find the number of transitive relations on a set with 3 elements. Use Java, C or PHP.
Solution
sing namespace std;
 const int num_nodes = 10;
 
 int main()
 {
 int num_nodes, k, n;
 char i, j, res, c;
 int adj[10][10], path[10][10];
 
 cout << \"\ \\tMaximum number of nodes in the graph :\";
 cin >> n;
 num_nodes = n;
 cout << \"\ \ \\tNODES ARE LABELED AS A,B,C,......\ \ \";
 cout << \"\ Enter \'y\'for \'YES\' and \'n\' for \'NO\' !!\ \";
 
 for (i = 65; i < 65 + num_nodes; i++)
 for (j = 65; j < 65 + num_nodes; j++)
 {
 cout << \"\ \\tIs there an EDGE from \" << i << \" to \" << j << \" ? \";
 cin >> res;
 if (res == \'y\')
 adj[i - 65][j - 65] = 1;
 else
 adj[i - 65][j - 65] = 0;
 }
 cout << \"\ Adjacency Matrix:\ \";
 
 cout << \"\ \\t\\t\\t \";
 for (i = 0; i < num_nodes; i++)
 {
 c = 65 + i;
 cout << c << \" \";
 }
 cout << \"\ \ \";
 for (int i = 0; i < num_nodes; i++)
 {
 c = 65 + i;
 cout << \"\\t\\t\\t\" << c << \" \";
 for (int j = 0; j < num_nodes; j++)
 cout << adj[i][j] << \" \";
 cout << \"\ \";
 }
 for (int i = 0; i < num_nodes; i++)
 for (int j = 0; j < num_nodes; j++)
 path[i][j] = adj[i][j];
 
 for (int k = 0; k < num_nodes; k++)
 for (int i = 0; i < num_nodes; i++)
 if (path[i][k] == 1)
 for (int j = 0; j < num_nodes; j++)
 path[i][j] = path[i][j] || path[k][j];
 
 for (int i = 0; i < num_nodes; i++)
 for (int j = 0; j < num_nodes; j++)
 adj[i][j] = path[i][j];
 
 cout << \"\ Transitive Closure of the Graph:\ \";
 
 cout << \"\ \\t\\t\\t \";
 for (i = 0; i < num_nodes; i++)
 {
 c = 65 + i;
 cout << c << \" \";
 }
 cout << \"\ \ \";
 for (int i = 0; i < num_nodes; i++)
 {
 
 c = 65 + i;
 cout << \"\\t\\t\\t\" << c << \" \";
 for (int j = 0; j < num_nodes; j++)
 cout << adj[i][j] << \" \";
 cout << \"\ \";
 }
 return 0;
 }


