Largest number that is not a perfect square | PHP program to find the largest non perfect square number among n numbers ; takes the sqrt of the number ; checks if it is a perfect square number ; function to find the largest non perfect square number ; stores the maximum of all non perfect square numbers ; traverse for all elements in the array ; store the maximum if not a perfect square ; Driver Code ; function call
< ? php function check ( $ n ) { $ d = sqrt ( $ n ) ; if ( $ d * $ d == $ n ) return true ; return false ; } function largestNonPerfectSquareNumber ( $ a , $ n ) { $ maxi = -1 ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) { if ( ! check ( $ a [ $ i ] ) ) $ maxi = max ( $ a [ $ i ] , $ maxi ) ; } return $ maxi ; } $ a = array ( 16 , 20 , 25 , 2 , 3 , 10 ) ; $ n = count ( $ a ) ; echo largestNonPerfectSquareNumber ( $ a , $ n ) ; ? >