Check if a number is a perfect square having all its digits as a perfect square | C ++ program for the above approach ; Function to check if digits of N is a perfect square or not ; Iterate over the digits ; Extract the digit ; Check if digit is a perfect square or not ; Divide N by 10 ; Return true ; Function to check if N is a perfect square or not ; If floor and ceil of n is not same ; Function to check if N satisfies the required conditions or not ; If both the conditions are satisfied ; Driver Code ; Function Call
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool check_digits ( long N ) { while ( N > 0 ) { int n = N % 10 ; if ( ( n != 0 ) && ( n != 1 ) && ( n != 4 ) && ( n != 9 ) ) { return 0 ; } N = N / 10 ; } return 1 ; } bool is_perfect ( long N ) { long double n = sqrt ( N ) ; if ( floor ( n ) != ceil ( n ) ) { return 0 ; } return 1 ; } void isFullSquare ( long N ) { if ( is_perfect ( N ) && check_digits ( N ) ) { cout << " Yes " ; } else { cout << " No " ; } } int main ( ) { long N = 144 ; isFullSquare ( N ) ; return 0 ; }