// 推断一个数是不是2的n次方 #include <stdio.h> void judge_n(int a) { int b = a - 1; if ((a & b) == 0) { printf("是2的n次方 "); return; } else { printf("不是2的n次方 "); return; } } int main() { judge_n(2); judge_n(3); judge_n(4); return 0; }