text: Logarithm tricks for Competitive Programming | C implementation to check that a integer is a power of Two ; Function to check if the number is a power of two ; Driver Code
code: #include <stdio.h> NEW_LINE #include <math.h> NEW_LINE _Bool isPowerOfTwo ( int n ) { return ( ceil ( log2 ( n ) ) == floor ( log2 ( n ) ) ) ; } int main ( ) { int N = 8 ; if ( isPowerOfTwo ( N ) ) { printf ( " Yes " ) ; } else { printf ( " No " ) ; } }