-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathcode with floyds algo.cpp
57 lines (56 loc) · 1.23 KB
/
code with floyds algo.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
52
53
54
55
56
57
#include <stdio.h>
#include <time.h>
#include <math.h>
int mat[10][10], d_mat[10][10], n;
void Floyd()
{
int i, j, k;
for (i = 0; i < n; i++)
{
for (j = 0; j < n; j++)
{
d_mat[i][j] = mat[i][j];
}
}
for (k = 0; k < n; k++)
{
for (i = 0; i < n; i++)
{
for (j = 0; j < n; j++)
{
if (d_mat[i][j] > (d_mat[i][k] + d_mat[k][j]))
d_mat[i][j] = (d_mat[i][k] + d_mat[k][j]);
}
}
}
}
void main()
{
clock_t start, end;
double t;
int i, j;
printf("Enter the total number of routes:\n");
scanf("%d", &n);
printf("Enter the connection between the house and the firestation in an matrix representation:\n");
for (i = 0; i < n; i++)
{
for (j = 0; j < n; j++)
{
scanf("%d", &mat[i][j]);
}
}
start = clock();
Floyd(mat);
end = clock();
printf("The Shortest path Matrix is \n");
for (i = 0; i < n; i++)
{
for (j = 0; j < n; j++)
{
printf("%d\t", d_mat[i][j]);
}
printf("\n");
}
t = (double)(end - start) / CLOCKS_PER_SEC;
printf("Time required : %f\n", t);
}