本文介绍了一个C问题。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨:

有关C编程的问题:

只使用一个C语句检查变量是否为2的幂。否
$允许b $ b循环。

等待你的答案。我几天没有睡好了。

Hi:
There is question about C programming:
Use just one C statement to check whether a variable is the power of 2. No
loops allowed.
Waiting for your answer.I have not slept well a few days for this.

推荐答案




int is_power_of_two(double x){

返回x> 0.0; / *一个声明,没有循环* /

}


美梦!


-

Eric Sosman
lid



int is_power_of_two(double x) {
return x > 0.0; /* one statement, no loops */
}

Sweet dreams!

--
Eric Sosman
es*****@acm-dot-org.invalid






puts(x&(x-1)|| x == 0?" not not power of two:power of two);


Robert Gamble



puts(x & (x-1) || x==0 ? "not a power of two" : "power of two");

Robert Gamble


这篇关于一个C问题。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 03:00