PROGRAM TRI

   IMPLICIT NONE

   ! Declarations
   INTEGER :: n, i, j, jmin
   REAL :: umax, umin
   REAL, DIMENSION(100) :: u, v

   ! Instructions
   WRITE(*,*) "Donner le nb d'elements a trier" 
   READ(*,*) n
   DO i = 1, n
      WRITE(*,*) 'Valeur du', i, 'eme element?'
      READ(*,*) u(i)
   END DO
   umax = u(1) 
   DO i = 2, n                 ! Determination du max de u 
       IF( u(i) >= umax ) umax = u(i)
   END DO
   DO i = 1, n            ! Recherche du min + indice de u
       jmin = 1
       umin = umax
       DO j = 1, n
            IF ( u(j) <= umin ) THEN
                  umin = u(j)
                  jmin = j
             END IF
        END DO
        v(i) = umin                ! Met la valeur min dans v
        u(jmin) = umax         ! Ecrase la valeur min de u
   END DO
   WRITE(*,*) 'Les element tries sont:'
   WRITE(*,*) ( v(i), i = 1, n )

END PROGRAM TRI
