### C++ program to implement Floyd-Warshal's algorithm for finding all pair shortest path.

**Aim:-**C++ program to implement Floyd-Warshal's algorithm for finding all pair shortest path.

**Input:-**No. of vertices or node of graph.

*1.**Adjacency cost matrix.*

**2.****Output:-**Shortest path for all possible two nodes.

**Source Code:-**

#include

#include

#define max 10

void allpairshort(int a[max][max][max],int n)

{

int i,j,k;

for(k=1;k<=n;k++)

{

for(i=1;i<=n;i++)

{

for(j=1;j<=n;j++)

{

if(a[k-1][i][j]<(a[k-1][i][k]+a[k-1][k][j]))

{

a[k][i][j]=a[k-1][i][j];

}

else

{

a[k][i][j]=a[k-1][i][k]+a[k-1][k][j];

}

}

}

}

cout<<"\nAll pair Shortest path is=\n";

for(i=1;i<=n;i++)

{

for(j=1;j<=n;j++)

{

cout<}

cout<<"\n";

}

}

void main()

{

int a[max][max][max],i,j,n;

clrscr();

cout<<"\nEnter no. of nodes:";

cin>>n;

cout<<"\n(Enter 999 for infinity";

cout<<"\nEnter adjacency cost matrix:";

for(i=1;i<=n;i++)

{

for(j=1;j<=n;j++)

{

cin>>a[0][i][j];

}

}

allpairshort(a,n);

getch();

}

This comment has been removed by the author.

ReplyDelete