Created
April 20, 2017 13:40
-
-
Save shubham100795/5161b2a013863a6b0d1dea97d7b4e558 to your computer and use it in GitHub Desktop.
Warshall's algorithm to find the path matrix
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<iostream> | |
using namespace std; | |
int main() | |
{ | |
int ar[4][4]={{0,1,0,1},{1,0,1,1},{0,0,0,1},{1,0,1,0}}; | |
for(int k=0;k<4;k++) | |
{ | |
for(int i=0;i<4;i++) | |
{ | |
for(int j=0;j<4;j++) | |
{ | |
ar[i][j]=(ar[i][j]||(ar[i][k]&&ar[k][j])); | |
} | |
} | |
cout<<"P"<<k<<" is"<<endl; | |
for(int i=0;i<4;i++) | |
{ | |
for(int j=0;j<4;j++) | |
{ | |
cout<<ar[i][j]<<" "; | |
} | |
cout<<endl; | |
} | |
cout<<endl; | |
} | |
cout<<"P3 is the path matrix"<<endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment