-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWarshall.cpp
More file actions
58 lines (52 loc) · 1011 Bytes
/
Warshall.cpp
File metadata and controls
58 lines (52 loc) · 1011 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include<iostream>
#include<iomanip>
using namespace std;
void warshall(int g[10][10],int n)
{
for(int k=0;k<n;k++)
{
for(int j=0;j<n;j++)
{
for(int i=0;i<n;i++)
{
if(g[i][j]||g[i][k]&&g[k][j])
g[i][j]=1;
}
}
}
cout<<"\nTransitive Matrix is :\n";
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
cout<<g[i][j]<<"\t";
}
cout<<"\n";
}
}
int main()
{
int n;
cout<<"Enter total Rows:";
cin>>n;
int g[10][10];
cout<<"Enter Matrix:\n";
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
cin>>g[i][j];
}
}
cout<<"Adjacency Matrix is :\n";
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
cout<<g[i][j]<<"\t";
}
cout<<"\n";
}
warshall(g,n);
return 0;
}