lab3 A
#include<stdio.h>
int main()
{
int i,j,k,n,d[10][20];
printf("Enter the number of vertices \n");
scanf("%d",&n);
printf("Enter the cost adjacent matrix \n");
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
scanf("%d",&d[i][j]);
}
}
for(k=1;k<=n;k++)
{
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
if((d[i][k] + d[k][j])<d[i][j])
{
d[i][j]=d[i][k] + d[k][j];
}
}
}
}
printf("All Pair shortest Path Matrix \n");
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
if(d[i][j]==999)
{
printf("%s\t","INF");
}
else
{
printf("%d\t",d[i][j]);
}
}
printf("\n");
}
}
lab 3b
#include<stdio.h>
int main()
{
int i,j,k,n,d[10][20];
printf("Enter the number of vertices \n");
scanf("%d",&n);
printf("Enter the cost adjacent matrix \n");
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
scanf("%d",&d[i][j]);
}
}
for(k=1;k<=n;k++)
{
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
d[i][j]=d[i][j]||(d[i][k]&&d[k][j]);
}
}
}
printf("The Transitive Closure of the given graph is \n");
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
printf("%d\t",d[i][j]);
}
printf("\n");
}
}