C
      PROGRAM MNEW
C
      IMPLICIT REAL*8(A-H,O-Z)
      COMPLEX*16 SS,FNC
      EXTERNAL FNC
C
      WRITE(*,1220)
      READ(*,*)NS
C
 1220 FORMAT( ' Enter div. num. for intergral   : ',\)
C
      CALL NEWTON(FNC,0.D0,3.1415927D0,NS,SS,IER)
      IF(IER.NE.0)WRITE(*,*)' IER=',IER,'!!!!!!!!!!'
C
      WRITE(*,*)'SS(=(2,0))',SS
C
      STOP
      END
C
C
C
      COMPLEX FUNCTION FNC*16 (X)
C
      IMPLICIT REAL*8(A-H,O-Z)
C
      FNC=DCMPLX(DSIN(X),DCOS(X))
C
      RETURN
      END
C
C
C
      SUBROUTINE NEWTON (FUNC,A,B,N,S,IER)
C
      IMPLICIT REAL*8(A-H,O-Z)
      COMPLEX*16 FUNC,Y,FX,Q,S
C
      IER = 0
      IF( N-1 ) 100,110,110
  100 IER=2000
      S=(0.D0,0.D0)
      GO TO 9999
      IF(A.EQ.B)THEN
        IER=2000
        GO TO 9999
      END IF
C
  110 H=(B-A)/N
      Y   = FUNC(A)
      Q=(0.D0,0.D0)
C
      DO  120 I=1,N
      X=A+H*I
      FX = FUNC(X)
      Q   = Q+H*(Y+FX)/2.D0
      Y   = FX
  120 CONTINUE
C
      S = Q
 9999 CONTINUE
      IER=0
      RETURN
C
      END
