0% found this document useful (0 votes)
15 views3 pages

Exp07 Aoa

Uploaded by

wemeval254
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views3 pages

Exp07 Aoa

Uploaded by

wemeval254
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

NAME : ABHAYKUMAR BHARTI SEB220

EXPERIMENT NO : 07

All pair Shortest Path: Floyd Warshall Algorithm

#include <stdio.h>

#include <stdlib.h>

void floydWarshall(int **graph, int n)

int i, j, k;

for (k = 0; k < n; k++)

for (i = 0; i < n; i++)

for (j = 0; j < n; j++)

if (graph[i][j] > graph[i][k] + graph[k][j])

graph[i][j] = graph[i][k] + graph[k][j];

int main(void)

int n, i, j;

printf("PROGRAM FOR ALL PAIR SHORTEST PATH : FLOYD WARSHALL ALGORITHM");

printf("\nEnter the number of vertices: ");

scanf("%d", &n);

int **graph = (int **)malloc((long unsigned) n * sizeof(int *));

for (i = 0; i < n; i++)


{

graph[i] = (int *)malloc((long unsigned) n * sizeof(int));

for (i = 0; i < n; i++)

for (j = 0; j < n; j++)

if (i == j)

graph[i][j] = 0;

else

graph[i][j] = 100;

printf("Enter the edges: \n");

for (i = 0; i < n; i++)

for (j = 0; j < n; j++)

printf("[%d][%d]: ", i, j);

scanf("%d", &graph[i][j]);

printf("The original graph is:\n");

for (i = 0; i < n; i++)

for (j = 0; j < n; j++)

printf("%d ", graph[i][j]);

printf("\n");

}
floydWarshall(graph, n);

printf("The shortest path matrix is:\n");

for (i = 0; i < n; i++)

for (j = 0; j < n; j++)

printf("%d ", graph[i][j]);

printf("\n");

return 0;

You might also like