      PROGRAM ADD
c     MAIN PROGRAM
c     HERE MAIN PROGRAM AND SUBROUTINE(S) ARE IN THE
c     SAME FILE: 'ADD.f'. BUT, ALSO ANOTHER
c     POSSIBILITY EXISTS. WE SHALL DISCUSS IT LATER.

c     DECLARATIONS
      integer N,p
      real*8 A

c     PRESENTATION AND READING THE NECESSERY DATA FOR
c     SUBROUTINE
    1 write(*,*)'PROGRAM ADD'
      write(*,*)'PLEASE GIVE N'
      read (*,*) N

c     CALLING SUBROUTINE
      call SUBADD(N)

c     WHAT THE PROGRAM HAS TO DO AT THE END ?
      write(*,*)'0 END'
      write(*,*)'1 NEW'
      read (*,*) p
c     IF YOU WRITE ON THE KEYBOARD "0"  - THE PROGRAM STOPS
c     IF YOU WRITE ON THE KEYBOARD "1"  - THE PROGRAM 
c     WILL WAIT FOR NEW DATA
      if(p.eq.0)then
      goto 100
      else
      goto 1
      endif

  100 stop 100
      end


c     SUBROUTINE
      subroutine SUBADD(N)

c     DECLARATIONS OF VARIABLES USED IN SUBROUTINE
      integer N,k
      real*8 A,O,SUM
      dimension A(N)

c     REAL*8 CONSTANT ZERO
      O=real(0)

c     FIRST LOOP: READING DATA AND CONTROL OUTPUT
      write(*,*)'PLEASE INTRODUCE DATA'
      do k=1,N,1
      read (*,*) A(k)
      enddo

c     SECOND LOOP: ADDING
      SUM=O
      do k=1,N,1
      write(*,*)' k=','A=', A(k)
      SUM=SUM+A(k)
      enddo

c     OUTPUT OF THE RESULT
      write(*,*)' SUM=',SUM 

c     END OF THE SUBROUTINE:
c     BACK TO MAIN PROGRAM
      return
      end