My Profile
Active Members
TodayLast 7 Days
more...
Awards & Gifts
Online Exams
Fresher Jobs
Our fresher job section is exclusively for fresh graduates! Find jobs for freshers in major Indian
cities including Bangalore, Chennai, Hyderabad, Pune or Kochi
Resources
Find educational articles, blogs, discussion threads and other resources.
Colleges
Find details about any college in India or search for courses.
|
Resources » Articles/Knowledge Sharing » Computer & Technology »
C Program to find path matrix by Warshall's algorithm
|
/* Program to find path matrix by Warshall's algorithm */ #include #define MAX 20 main() { int i,j,k,n; int w_adj[MAX][MAX],adj[MAX][MAX],path[MAX][MAX];
printf("Enter number of vertices : "); scanf("%d",&n);
printf("Enter weighted adjacency matrix :\n"); for(i=0;i for(j=0;j scanf("%d",&w_adj[i][j]);
printf("The weighted adjacency matrix is :\n"); display(w_adj,n);
/* Make weighted adjacency matrix into boolean adjacency matrix*/ for(i=0;i for(j=0;j if(w_adj[i][j]==0) adj[i][j]=0; else adj[i][j]=1;
printf("The adjacency matrix is :\n"); display(adj,n);
for(i=0;i for(j=0;j path[i][j]=adj[i][j];
for(k=0;k { printf("P%d is :\n",k); display(path,n); for(i=0;i for(j=0;j path[i][j]=( path[i][j] || ( path[i][k] && path[k][j] ) ); } printf("Path matrix P%d of the given graph is :\n",k); display(path,n); }/*End of main() */
display(int matrix[MAX][MAX],int n) { int i,j; for(i=0;i { for(j=0;j printf("%3d",matrix[i][j]); printf("\n"); }
}/*End of display()*/
|
Responses
|
No responses found. Be the first to respond and make money from revenue sharing program.
|
|
Advertise Here
Watch TV Channels
|