-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy path16-warshall.c
44 lines (39 loc) · 952 Bytes
/
16-warshall.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
#include <stdio.h>
#include <stdlib.h>
int main()
{
int n = 4;
int i, j, k;
int R[5][5] = {
{0, 0, 0, 0, 0},
{0, 0, 1, 0, 0},
{0, 0, 0, 0, 1},
{0, 0, 0, 0, 0},
{0, 1, 0, 1, 0}
};
printf("The supplied input is\n");
for(i = 1; i <= n; i++){
for(j = 1; j<= n; j++){
printf("%d\t", R[i][j]);
}
printf("\n");
}
for(k = 1; k <= n; k++) {
for(i = 1; i <= n; i++) {
for(j = 1; j <= n; j++) {
if(R[i][j] != 1){
if(R[i][k] == 1 && R[k][j] == 1)
R[i][j] = 1;
}
}
}
}
printf("Transitive Closure:\n");
for(i = 1; i <= n; i++){
for(j = 1; j<= n; j++){
printf("%d\t", R[i][j]);
}
printf("\n");
}
return 0;
}