! This is a basic starting shell for your programs MODULE const INTEGER, PARAMETER :: dp = KIND(1.0d0), sp = KIND(1.0e0) REAL(KIND=dp), PARAMETER :: dpi = 3.141592653589793d0 END MODULE const ! PROGRAM prog USE const IMPLICIT NONE ! ! Program to implement the trapezoidal rule for ! the integral of x^2 + x + 1 on the interval [-1,2]. ! INTEGER :: n,i REAL(kind=dp) :: a,b,h,x,f,total ! Set integral limits and value of n a = -1 b = 2 n = 10 ! Compute h h = (b-a)/n ! Main accumulation loop total = 0 DO i = 1,n+1 ! Get x and f value for current table row x = a + (i-1)*h f = x**2 + x + 1 ! Accumulate function values IF((i == 1).OR.(i == n+1)) THEN total = total + f ELSE total = total + 2*f ENDIF ENDDO ! Multiply by h/2 to get approximate integral value total = total*h/2 WRITE(*,*) 'Approximate integral = ',total END PROGRAM prog