Source Code:
#include<iostream.h>
#include<conio.h>
void main()
{clrscr();
int g[10][10],n,i,j,k;
cout<<"program for Floyd warshall (all pair shortest path)by: Tarun rawat\n\n";
cout<<"Enter number of vertices n= ";
cin>>n;
cout<<"Enter n*n adjacency matrix \n";
for(i=0;i<n;i++)
{for(j=0;j<n;j++)
{ cin>>g[i][j];
}
}
for(k=0;k<n;k++)
{for(i=0;i<n;i++)
{
if (g[i][k]>0)
{for(j=0;j<n;j++)
{if(g[k][j]>0 && g[i][j]>(g[i][k]+g[k][j]))
{g[i][j]=g[i][k]+g[k][j];
}
}
}
}
}
cout<<"\nOutput : \n";
for(i=0;i<n;i++)
{for(j=0;j<n;j++)
{ cout<<g[i][j]<<" ";
}
cout<<"\n";
}
getch();
}
Welcome to " way2cplusplus.blogspot.in " Objective of this blog is to implement various Computer Science Engineering Lab problems into C++ programming language. These are basically most common Lab Exercise problems based on the curriculum of engineering colleges throughout the Nation. These lab exercises are also relevant to Data structure. Simply C++ programming zone...
ReplyDeletenice article for beginners.thank you.
javacodegeeks
welookups
Thanks for sharing nice information about C++ . Keep Sharing..
ReplyDeleteGood Post. I like your blog. Thanks for Sharing.
ReplyDeleteC C++ Training in Noida
Cool and that i have a neat supply: What Renovations Can You Claim On Tax house renovation ideas interior
ReplyDelete