c**********************************************************************
c   pi.f - compute pi by integrating f(x) = 4/(1 + x**2)     
c   SEQUENTIAL VERSION  
c
c  Variables:
c
c    pi  the calculated result
c    n   number of points of integration.  
c    x           midpoint of each rectangle's interval
c    f           function to integrate
c    i           do loop index
c****************************************************************************
      program main
      double precision  PI25DT
      parameter        (PI25DT = 3.141592653589793238462643d0)
      double precision  pi, h, sum, x, f, a
      integer n, i
c     /* function to integrate */
      f(a) = 4.d0 / (1.d0 + a*a)
      print *, 'SEQUENTIAL VERSION'
c     /* input of the number of intervals */
 10   write(6,98)
 98   format('Enter the number of intervals: (0 quits)')
      read(5,99) n
 99   format(i10)
c     /* check for quit signal */
      if ( n .le. 0 ) goto 30
c     /* calculate the interval size */
      h = 1.0d0/n
c     /* perform the rectangular summation */
      sum  = 0.0d0
      do 20 i = 1, n
         x = h * (dble(i) - 0.5d0)
         sum = sum + f(x)
 20   continue
      pi = h * sum
c     /* print result to screen */
      write(6, 97) pi, abs(pi - PI25DT)
 97   format('  pi is approximately: ', F18.16,
     +     '  Error is: ', E20.15)
c
      goto 10
 30   stop
      end



