program reverse_array
  implicit none
  integer,parameter::size=30
  integer,dimension(1:size)::a
  integer::n,head,tail,temp,i

  read(*,*) n
  read(*,*) (a(i),i=1,n)
  write(*,*) 'input array:'
  write(*,*) (a(i),i=1,n)

  head=1
  tail=n
  do
    if(head>=tail) exit
    temp=a(head)
    a(head)=a(tail)
    a(tail)=temp
    head=head+1
    tail=tail-1
  enddo
  write(*,*) 'reversed array:'
  write(*,*) (a(i),i=1,n)
  stop 'array reversed'
end program reverse_array
