Largest perfect square number in an Array | C # program to find the largest perfect square number among n numbers ; Function to check if a number is perfect square number or not ; takes the sqrt of the number ; checks if it is a perfect square number ; Function to find the largest perfect square number in the array ; stores the maximum of all perfect square numbers ; Traverse all elements in the array ; store the maximum if current element is a perfect square ; Driver Code
using System ; class GFG { static bool checkPerfectSquare ( double n ) { double d = Math . Sqrt ( n ) ; if ( d * d == n ) return true ; return false ; } static int largestPerfectSquareNumber ( int [ ] a , double n ) { int maxi = - 1 ; for ( int i = 0 ; i < n ; i ++ ) { if ( checkPerfectSquare ( a [ i ] ) ) maxi = Math . Max ( a [ i ] , maxi ) ; } return maxi ; } public static void Main ( ) { int [ ] a = { 16 , 20 , 25 , 2 , 3 , 10 } ; double n = a . Length ; Console . WriteLine ( largestPerfectSquareNumber ( a , n ) ) ; } }