-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWarshall's Algorithm
More file actions
58 lines (54 loc) · 770 Bytes
/
Warshall's Algorithm
File metadata and controls
58 lines (54 loc) · 770 Bytes
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
#include<stdio.h>
#include<stdlib.h>
int **a,n;
void warshall()
{
int i,j,k;
for(k=0;k<n;k++)
{
for(j=0;j<n;j++)
{
for(i=0;i<n;i++)
{
a[i][j]=a[i][j]||a[i][k]&&a[k][j];
}
}
}
}
void print_array()
{
int i,j;
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
printf("%d\t",a[i][j]);
}
printf("\n");
}
}
int main()
{
int i,j;
printf("Number of vertices:");
scanf("%d",&n);
a=calloc(n,sizeof(int*));
for(i=0;i<n;i++)
{
a[i]=calloc(n,sizeof(int));
}
printf("Adjacency Matrix:\n");
for(i=0;i<n;i++)
{
for(j=0;j<n ;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("Entered Adjacency Matrix:\n");
print_array();
warshall();
printf("Transitive Closure Matrix:\n");
print_array();
return 0;
}