0% found this document useful (0 votes)
5 views1 page

C Program for Graph Transitive Closure

The document provides a C program that implements Warshall's algorithm to compute the transitive closure of a directed graph. It includes functions to initialize the adjacency matrix, compute the path matrix, and display the results. The program prompts the user for the number of nodes and the adjacency matrix, then outputs the resulting path matrix.

Uploaded by

Amar A
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views1 page

C Program for Graph Transitive Closure

The document provides a C program that implements Warshall's algorithm to compute the transitive closure of a directed graph. It includes functions to initialize the adjacency matrix, compute the path matrix, and display the results. The program prompts the user for the number of nodes and the adjacency matrix, then outputs the resulting path matrix.

Uploaded by

Amar A
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

7.

Write a C program to compute the transitive closure of a given directed graph using
Warshall's algorithm.

# include <stdio.h>

int n,a[10][10],p[10][10];
void path()
{
int i,j,k;
for(i=0;i<n;i++)
for(j=0;j<n;j++)
p[i][j]=a[i][j];
for(k=0;k<n;k++)
for(i=0;i<n;i++)
for(j=0;j<n;j++)
if(p[i][k]==1&&p[k][j]==1)
p[i][j]=1;
}

void main()
{
int i,j;
printf("Enter the number of nodes:");
scanf("%d",&n);
printf("\nEnter the adjacency matrix:\n");
for(i=0;i<n;i++)
for(j=0;j<n;j++)
scanf("%d",&a[i][j]);
path();
printf("\nThe path matrix is showm below\n");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
printf("%d ",p[i][j]);
printf("\n");
}
}

You might also like