Check whether the product of every subsequence is a perfect square or not | C ++ program for the above approach ; Function to check if the product of every subsequence of the array is a perfect square or not ; Traverse the given array ; If arr [ i ] is a perfect square or not ; Return " Yes " ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; string perfectSquare ( int arr [ ] , int N ) { for ( int i = 0 ; i < N ; i ++ ) { int p = sqrt ( arr [ i ] ) ; if ( p * p != arr [ i ] ) { return " No " ; } } return " Yes " ; } int main ( ) { int arr [ ] = { 1 , 4 , 100 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << perfectSquare ( arr , N ) ; return 0 ; }