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