!     Last change:  CSM  19 Oct 2004   10:13 am
!*****************************************!
! Amy Vess                                !
! CS 252 Homework - October 19, 2004      !
!*****************************************!

PROGRAM homework

IMPLICIT NONE

INTEGER:: n, i  !n = number of iterations, i is a counter
REAL:: a, r, summ, summ2 !a = initial term, r = common ratio
                !summ = the sum of the first n terms by iteration
                !summ2 = the sum found by the formula

!Reads input from the screen
WRITE (*,*) "Enter the number of iterations: "
READ (*,*) n
WRITE (*,*) "Enter the initial term, a: "
READ (*,*) a
WRITE (*,*) "Enter the common ratio, r: "
READ (*,*) r


!Computes the sum through iteration
summ = 0
DO i = 0,n-1
    summ = summ + (a * (r**i))
END DO

WRITE (*,*) "Using iteration, the sum of the first n terms is: ", summ


!Computes the sum using the formula from Exercise 23 on pg. 106
summ2 = (a - (a * (r**n) ) ) / (1 - r)

WRITE (*,*) "Using the formula, the sum of the first n terms is: ", summ2

STOP
END PROGRAM homework
