program exercise implicit none integer :: n,np,i,k real*8, allocatable :: a(:) integer, allocatable :: tmp(:) real*8 :: even,odd !1) do write(*,*) 'Array size (>1)' read(*,*) n if (n.gt.1) exit enddo allocate(a(n)) write(*,*) 'Array' read(*,*) a !2) even=0.d0 do i=2,n,2 even=even+a(i) enddo odd=0.d0 do i=1,n,2 odd=odd+a(i) enddo write(*,*) 'Value of even', even write(*,*) 'Value of odd', odd !3) np=n/2 if (even.gt.odd) then allocate(tmp(np)) k=0 do i=2,n,2 k=k+1 tmp(k)=int(a(i)) enddo call bubblep(tmp,np) else if (mod(n,2).ne.0) np=np+1 allocate(tmp(np)) k=0 do i=1,n,2 k=k+1 tmp(k)=int(a(i)) enddo call bubblem(tmp,np) endif !4) open(10,file='out.dat') do i=1,np write(10,100) i,tmp(i) enddo close(10) deallocate(a) deallocate(tmp) 100 format(2(I4)) stop end program exercise subroutine bubblep(x,n) implicit none integer, intent(in) :: n integer, intent(inout) :: x(n) integer :: i,j do i=1,n do j=2,n-(i-1) if (x(j-1).gt.x(j)) then call swap(x(j-1),x(j)) endif enddo enddo return end subroutine bubblep subroutine bubblem(x,n) implicit none integer, intent(in) :: n integer, intent(inout) :: x(n) integer :: i,j do i=1,n do j=2,n-(i-1) if (x(j-1).lt.x(j)) then call swap(x(j-1),x(j)) endif enddo enddo return end subroutine bubblem subroutine swap(x,y) implicit none integer, intent(inout) :: x,y integer :: tmp tmp=x x=y y=tmp return end subroutine swap