Largest sub | C ++ program to find the length of the largest sub - array of an array every element of whose is a perfect square ; function to return the length of the largest sub - array of an array every element of whose is a perfect square ; if both a and b are equal then arr [ i ] is a perfect square ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int contiguousPerfectSquare ( int arr [ ] , int n ) { int a ; float b ; int current_length = 0 ; int max_length = 0 ; for ( int i = 0 ; i < n ; i ++ ) { b = sqrt ( arr [ i ] ) ; a = b ; if ( a == b ) current_length ++ ; else current_length = 0 ; max_length = max ( max_length , current_length ) ; } return max_length ; } int main ( ) { int arr [ ] = { 9 , 75 , 4 , 64 , 121 , 25 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << contiguousPerfectSquare ( arr , n ) ; return 0 ; }