100 DEFDBL A-H, O-Z
105 DEF FNA (x AS DOUBLE) = SQR(1! - (SIN(EXP(1) / 2!) * SIN(x)) ^ 2)
110 A = 0!: REM This is the lower endpoint of [a,b].
120 B = 3.141592653589793# / 2!: REM This is the upper endpoint of [a,b].
130 SUM = 0!: REM This is an accumulator.
135 REM The user is asked for a number of intervals, n, even and > 0.
140 INPUT "Enter number of intervals (must be even) "; N
145 IF N <= 0 OR (2 * FIX(N / 2) - N < 0) THEN PRINT "Input error": GOTO 140
150 H = (B - A) / N: REM The sub-interval size h = (b-a)/n.
160 FOR I = 1 TO N STEP 2: REM The "FOR" loop is done n/2 times.
170 SUM = SUM + FNA(A + (I - 1) * H)
175 REM: PRINT A + (I - 1) * H, FNA(A + (I - 1) * H)
180 SUM = SUM + 4! * FNA(A + I * H)
185 REM: PRINT A + I * H, FNA(A + I * H)
190 SUM = SUM + FNA(A + (I + 1) * H)
195 REM: PRINT A + (I + 1) * H, FNA(A + (I + 1) * H)
200 NEXT I: REM After loop, the sum is y_0+4*y_1+2*y_2+...+4*y_{n-1}+y_n.
210 PRINT "Sum = "; SUM: PRINT " Value of integral = "; SUM * H / 3
220 REM This short program will integrate a function FNA(x) from x = a to b.