Tweet
# include<stdio.h>
# define size 20
int a [size][size];
int p [size][size];
int i,k,j;
int n;
void Input ();
void Warshall ();
void Output ();
void Input()
{
printf("\n Input the number of vertices: ");
scanf("%d", &n);
printf("\n Input adjency matrix\n");
for ( i = 0; i < n; i++)
{
for ( j = 0; j < n; j++)
{
scanf("%d", &a[i][j]);
}
printf("\n");
}
printf("\n Adjency matrix \n");
for ( i = 0; i < n; i++)
{
for ( j = 0; j < n; j++)
{
printf(" %d", a[i][j]);
}
printf("\n");
}
}
void Output()
{
for ( i = 0; i < n; i++)
{
for ( j = 0; j < n; j++)
{
printf(" %d", p [i][j]);
}
printf("\n");
}
}
void Warshall ()
{
for ( i = 0; i < n; i++)
{
for ( j = 0; j < n; j++)
{
if (a[i][j] == 0)
p [i][j] = 0;
else
p[i][j] = 1;
}
}
for ( k = 0; k < n; k++)
{
for ( i = 0; i < n; i++)
{
for ( j = 0; j < n; j++)
{
p[i][j] = p[i][j] / ( p[i][k] * p[k][j]);
}
}
}
}
void main()
{
Input ();
Warshall ();
printf("\n Path matrix:\n");
Output ();
}
Warshall's Algorithm Programming in C
Posted by
LAHAUL SETH
~
Warshall's Algorithm Programming in C
2012-02-09T17:10:00+05:30
LAHAUL SETH
Graphs
|
Comments
Warshall's Algorithm Programming in C
2012-02-09T17:10:00+05:30
LAHAUL SETH
Graphs
|