FUNC(X)=EXP(X)
EXACT=EXP(1.)-1.
c adapted for batch use, remove the 3 comments that start with c30
c immediately as well as the one far below
c and comment out the lines N= , the print statement
c and the line saying stop to return to interactive use
N=100
c30 PRINT *,'ENTER N EVEN (.LT. 2 TO STOP)'
c READ *, N
c IF (N .LT. 2) STOP
IF (MOD(N,2) .NE. 0) N=N+1
H=1./N
SUM=FUNC(0.)
FAC=2
DO 10 I=1,N-1
IF (FAC .EQ. 2.) THEN
FAC=4
ELSE
FAC=2.
END IF
X=I*H
SUM=SUM+FAC*FUNC(X)
10 CONTINUE
SUM=SUM+FUNC(1.)
XINT=SUM*H/3.
DIFF=EXACT-XINT
write(8,20)N,XINT,DIFF
c PRINT 20,N,XINT,DIFF
20 FORMAT (5X,'N=',I5,5X,'XINT=',E15.8,5X,'ERROR=',E15.8)
c GOTO 30
stop
END