-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwarshall.c
53 lines (43 loc) · 1.11 KB
/
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
45
46
47
48
49
50
51
52
53
#include <stdio.h>
void wrshl(int n, int a[20][20]) {
int i, j, k, m1[20][20], m2[20][20];
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
m1[i][j] = a[i][j];
}
}
for (k = 0; k < n; k++) {
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
m2[i][j] = (m1[i][j] || (m1[i][k] && m1[k][j]));
}
}
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
m1[i][j] = m2[i][j];
}
}
}
printf("Transitive closure of the given matrix is:\n");
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
printf("%d\t", m1[i][j]);
}
printf("\n");
}
}
void readmat() {
int a[20][20], n, i, j;
printf("Enter the number of vertices: ");
scanf("%d", &n);
printf("Enter the adjacency matrix:\n");
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
scanf("%d", &a[i][j]);
}
}
wrshl(n, a);
}
void main() {
readmat();
}