PROGRAM TravSaley IMPLICIT NONE INTEGER :: I,J,K,L,M INTEGER :: dist_travelled, min_dist=HUGE(0) INTEGER, PARAMETER :: n_towns=5 INTEGER, DIMENSION(6) :: route CHARACTER, DIMENSION(5) :: towns = (/'A','B','C','D','E'/) INTEGER, DIMENSION(n_towns,n_towns) :: dist= & RESHAPE( & (/ 0,120,180,202,300, & 120, 0,175,340,404, & 180,175, 0, 98, 56, & 202,340, 98, 0,168, & 300,404, 56,168, 0 /), (/5,5/) ) LI: DO I = 1, n_towns LJ: DO J = 1, n_towns IF (J==I) CYCLE LK: DO K = 1, n_towns IF (K==J .OR. K==I) CYCLE LL: DO L = 1, n_towns IF (L==J .OR. L==K .OR. L==I ) CYCLE LM: DO M = 1, n_towns IF (M==L .OR. M==K .OR. M==J .OR. M==I) CYCLE dist_travelled = dist(I,J) + dist(J,K) + dist(K,L) + & dist(L,M) + dist(M,I) IF (dist_travelled < min_dist) THEN min_dist = dist_travelled route(1) = I route(2) = J route(3) = K route(4) = L route(5) = M route(6) = I END IF END DO LM END DO LL END DO LK END DO LJ END DO LI PRINT*,'Shortest route travelled is :' DO I=1,n_towns+1 PRINT*,towns(route(I)) END DO PRINT*,'Distance travelled = ',min_dist END PROGRAM TravSaley