Top baner Big

Your Ad Here

Top Banner

Your Ad Here

Saturday, November 22, 2008

FLOYD WARSHALL'S ALGORITHM

/*Program : FLOYD WARSHALL'S ALGORITHM
Programmer ::fizmhd(MEA) www.mdown.co.cc*/



#include
#define inf 9999
int min(int a,int b);
main()
{
int i,j,n,k,a[20][20],p[20][20],t;
printf("ENTER THE NO. OF VERTICES ");
scanf("%d",&n);
printf("ENTER THE WEIGHTED ADJACENCY MATRIX");
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
scanf("%d",&a[i][j]);
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
{
if(a[i][j]==0)
p[i][j]=inf;
else
p[i][j]=a[i][j];
}
for(k=1;k<=n;k++)
{
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
{
t=p[i][k]+p[k][j];
p[i][j]=min(p[i][j],t);
}
}
printf("\nSHORTEST PATH IS\n");
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
if(p[i][j]==inf)
printf("- ");
else
printf("%d ",p[i][j]);
}
printf("\n");
}
}
int min(int a,int b)
{
if(areturn(a);
else
return(b);
}

No comments:

Easy Hits

EasyHits4U.com - Your Free Traffic Exchange - 1:1 Exchange Ratio, 5-Tier Referral Program. FREE Advertising!

Bottom Square