Check if a number is power of 8 or not | C ++ program to check if a number is power of 8 ; function to check if power of 8 ; calculate log8 ( n ) ; check if i is an integer or not ; driver function
#include <cmath> NEW_LINE #include <iostream> NEW_LINE using namespace std ; bool checkPowerof8 ( int n ) { double i = log ( n ) / log ( 8 ) ; return ( i - trunc ( i ) < 0.000001 ) ; } int main ( ) { int n = 65 ; checkPowerof8 ( n ) ? cout << " Yes " : cout << " No " ; return 0 ; }