program bubble_sort implicit none integer, allocatable :: a(:) integer :: i,n do write(*,*) 'Array length' read(*,*) n if (n.gt.0) exit enddo allocate(a(n)) write(*,*) 'Initial array' read(*,*) a call bubble(a,n) write(*,*)'Sorted array' write(*,*) a deallocate(a) stop end program bubble_sort subroutine bubble(a,n) implicit none integer, intent(in) :: n integer, intent(inout) :: a(n) integer :: i,j do i=1,n do j=2,n-(i-1) if (a(j-1).gt.a(j)) then call scambia(a(j-1),a(j)) endif enddo enddo return end subroutine bubble subroutine scambia(x,y) implicit none integer, intent(inout) :: x,y integer :: tmp tmp=x x=y y=tmp return end subroutine scambia