Sie sind auf Seite 1von 1

PROGRAM search_pi

IMPLICIT NONE
INTEGER:: I, J, total, indx, numdigs, counter
CHARACTER (1000000) :: pi_string
CHARACTER (100):: search_for_me
LOGICAL::found_one
OPEN(UNIT=11, FILE='PI1MILDS.txt')
READ(11,*)pi_string
PRINT*, 'Please input a sequence of digits to search for.'
READ*, search_for_me
numdigs=LEN_TRIM(search_for_me)
indx=INDEX(pi_string, TRIM(search_for_me))
total=0
DO I=1, 1000000
IF (search_for_me .EQ. pi_string(I:I)) THEN
total=total+1
END IF
END DO
PRINT*, 'Your sequence occurs', total, 'times!'
IF (indx==0) THEN
PRINT*, 'Not found in the first million digits of pi!'
ELSE
PRINT*, 'And the first occurrence is at', indx
PRINT*, pi_string(max(indx-8,1): indx - 1), ' ', &
pi_string(indx :indx+numdigs - 1), ' ', &
pi_string(indx+numdigs : min(indx+numdigs+7, 1000000))
END IF
CLOSE(11)
END PROGRAM search_pi

Das könnte Ihnen auch gefallen