Find whether a given number is a power of 4 or not | C ++ program to find whether a given number is a power of 4 or not ; Function to check if x is power of 4 ; Driver code
#include <iostream> NEW_LINE using namespace std ; #define bool  int NEW_LINE class GFG { public : bool isPowerOfFour ( int n ) { if ( n == 0 ) return 0 ; while ( n != 1 ) { if ( n % 4 != 0 ) return 0 ; n = n / 4 ; } return 1 ; } } ; int main ( ) { GFG g ; int test_no = 64 ; if ( g . isPowerOfFour ( test_no ) ) cout << test_no << " ▁ is ▁ a ▁ power ▁ of ▁ 4" ; else cout << test_no << " is ▁ not ▁ a ▁ power ▁ of ▁ 4" ; getchar ( ) ; }