Posts

Showing posts with the label Program to find the shortest path

Program to find the shortest path

Program to find the shortest path #include " " #include " " #define INF 9999 void main( ) { int arr[4][4] ; int cost[4][4] = { 7, 5, 0, 0, 7, 0, 0, 2, 0, 3, 0, 0, 4, 0, 1, 0 } ; int i, j, k, n = 4 ; clrscr( ) ; for ( i = 0 ; i { for ( j = 0; j { if ( cost[i][j] == 0 ) arr[i][j] = INF ; else arr[i][j] = cost[i][j] ; } } printf ( "Adjacency matrix of cost of edges:\n" ) ; for ( i = 0 ; i { for ( j = 0; j printf ( "%d\t", arr[i][j] ) ; printf ( "\n" ) ; } for ( k = 0 ; k { for ( i = 0 ; i { for ( j = 0 ; j { if ( arr[i][j] > arr[i][k] + arr[k][j] ) arr[i][j] = arr[i][k] + arr[k][j]; ...