PROGRAM partialsums
! this program demostrates the advantage of using partial sums
!   for large series of numbers
IMPLICIT NONE

INTEGER :: n
REAL, allocatable, dimension(:,:) :: a
REAL sum1, sum2, psum
REAL*8 sum3
INTEGER :: i,j

print *,'enter size of array dimension '
read(5,*)n
allocate(a(n,n))
! define array a
CALL RANDOM_NUMBER(a)
a = a + 1

sum1 = 0.0
sum2 = 0.0
sum3 = 0.0
DO j = 1,n
  psum = 0.0
  DO i = 1,n
    sum1 = sum1 + a(i,j)
    sum3 = sum3 + a(i,j)
    psum = psum + a(i,j)
  ENDDO
  sum2 = sum2 + psum
ENDDO
print *, sum1, sum2, sum3

END PROGRAM partialsums
