-
Notifications
You must be signed in to change notification settings - Fork 0
/
Floyds.cpp
51 lines (50 loc) · 925 Bytes
/
Floyds.cpp
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
#include<iostream>
#include<iomanip>
using namespace std;
int n;
int a[20][20];
void floyd()
{
int dist[n][n];
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
dist[i][j]=a[i][j];
}
}
for(int k=0;k<n;k++)
{
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
if(dist[i][k]+dist[k][j]<dist[i][j])
dist[i][j]=dist[i][k]+dist[k][j];
}
}
}
cout<<"Result:-\n";
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
cout<<dist[i][j]<<" ";
}
cout<<"\n";
}
}
int main()
{
cout<<"Enter Total Vertices :";
cin>>n;
cout<<"Enter Matrix:-\n";
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
cin>>a[i][j];
}
}
floyd();
}