program serial_pi implicit none integer n, i real*8 PI25DT parameter (PI25DT = 3.141592653589793238462643d0) real*8 pi, h, sum, x logical done done = .false. do while ( .not.done) print *, "Enter the number of intervals: (0 quits) " read(*,*) n if (n .eq. 0) exit h = 1.0d0/n sum = 0.0d0 do i = 1, n x = h * (i - 0.5d0) sum = sum + 4.0d0/(1.0d0 + x*x) enddo pi = h * sum print *, " pi is approximately ",pi, print *, " Error is ", abs(pi - PI25DT) end do stop end