PROGRAM LAB11

 

            IMPLICIT NONE

 

            INTEGER :: Lower_Ind_A, Upper_Ind_A, I, Flag

 

            REAL, DIMENSION(:), ALLOCATABLE :: A

 

            REAL :: Number

 

            ! Now we read the lower and the upper indices of array A.

 

            PRINT *, "Enter lower index of A followed by upper index:"

 

            READ *, Lower_Ind_A, Upper_Ind_A

 

            ! Now we MUST allocate a space for array A.

 

            ALLOCATE(A(Lower_Ind_A:Upper_Ind_A))

 

            ! Now we read the elements of A.

 

            PRINT *, "Enter elements of A"

 

            READ *, A

 

            ! Now we eneter the number which we want to search for.

 

            PRINT *, "Enter a number to search for:"

 

            READ *, Number

 

            ! Now we search array A for that number.

 

            Flag=0

 

            ! NOTE: Flag=0 means the entered number is not a member of A.

 

            ! Flag=1 means the entered number is a member of A.

 

            DO I= Lower_Ind_A, Upper_Ind_A

 

                        IF (A(I)==Number) THEN

 

                                    Flag=1

                                    Exit

                        END IF

 

            END Do

            IF (Flag==1) THEN

                        PRINT *, "YES"

            ELSE

                        PRINT *, "NO"

            END IF

 

            ! Now we need to free the space allocated for array A.

 

            DEALLOCATE(A)

 

END PROGRAM LAB11