27 lines
390 B
C
27 lines
390 B
C
//
|
|
// Created by aurora on 24-8-14.
|
|
//
|
|
|
|
#include <assert.h>
|
|
#include <stdbool.h>
|
|
|
|
bool isPowerOfTwo(int n)
|
|
{
|
|
if (n <= 0)
|
|
return false;
|
|
|
|
while (n / 2)
|
|
{
|
|
if (n % 2 != 0)
|
|
return false;
|
|
n /= 2;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
int main()
|
|
{
|
|
assert(isPowerOfTwo(2) == true);
|
|
assert(isPowerOfTwo(0) == false);
|
|
assert(isPowerOfTwo(1) == true);
|
|
} |