! ! This program written by Clint Whaley for CS 1073. It is an optional ! programming exercise given on 10/08/09. ! PROGRAM series3 ! ! This program prints out all entries in a series up to and including N, ! using the series definition: ! S(i) = S(i-1)*S(i-2) + S(i-3) ! The user is prompted for N and the seed values S(0), S(1), and S(2) ! IMPLICIT NONE INTEGER :: i, N DOUBLE PRECISION :: Smin3, Smin2, Smin1, S ! ! Prompt user for series number and seed values. ! PRINT *, 'Please enter the last sequence number (>= 0) to compute' READ *, N PRINT *, 'Please enter S0 S1 and S2 (separated by spaces)' READ *, Smin3, Smin2, Smin1 ! ! Do some basic error checking on numbers ! IF (N .LT. 0) THEN PRINT *, 'Negative N not allowed!' STOP END IF WRITE(*,1000) 0, Smin3 IF (N .EQ. 0) STOP WRITE(*,1000) 1, Smin2 IF (N .EQ. 1) STOP WRITE(*,1000) 2, Smin1 IF (N .EQ. 2) STOP ! ! Print the I=3 to N entries in the sequence ! DO i = 3, N S = Smin1*Smin2 + Smin3 WRITE(*,1000) i, S Smin3 = Smin2 Smin2 = Smin1 Smin1 = S END DO 1000 FORMAT('S', I3.3, ' = ', ES17.10) END PROGRAM series3