-
Notifications
You must be signed in to change notification settings - Fork 0
/
warshall's algorithm.c
41 lines (41 loc) · 1.05 KB
/
warshall's algorithm.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
#include <stdio.h>
const int MAX = 100;
void WarshallTransitiveClosure(int graph[MAX][MAX], int numVert);
int main(void)
{
int i, j, numVert;
int graph[MAX][MAX];
printf("Warshall's Transitive Closure\n");
printf("Enter the number of vertices : ");
scanf("%d",&numVert);
printf("Enter the adjacency matrix :-\n");
for (i=0; i<numVert; i++)
for (j=0; j<numVert; j++)
scanf("%d",&graph[i][j]);
WarshallTransitiveClosure(graph, numVert);
printf("\nThe transitive closure for the given graph is :-\n");
for (i=0; i<numVert; i++)
{
for (j=0; j<numVert; j++)
{
printf("%d\t",graph[i][j]);
}
printf("\n");
}
return 0;
}
void WarshallTransitiveClosure(int graph[MAX][MAX], int numVert)
{
int i,j,k;
for (k=0; k<numVert; k++)
{
for (i=0; i<numVert; i++)
{
for (j=0; j<numVert; j++)
{
if (graph[i][j] || (graph[i][k] && graph[k][j]))
graph[i][j] = 1;
}
}
}
}