program scope_3
  implicit none
  integer::i,max=5
  do i=1,max
    write(*,*) sum(i)
  enddo
contains
  integer function sum(n)
    implicit none
    integer,intent(in)::n
    integer::i,s
    s=0
    do i=1,n
      s=s+i
    enddo
    sum=s
  end function sum
end program scope_3
