一个C问题。 [英] A C Question.

查看:55
本文介绍了一个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.

推荐答案

Jack Young写道:
Jack Young wrote:
嗨:
有关C编程的问题:
只使用一个C语句检查变量是否是2的幂。否
允许循环。
等待你的回答。我几天没睡好了。
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
es ***** @ acm-dot-org.inva 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


if(var%2 == 0){

printf(" yep \ n");

}

if ( var % 2 == 0 ) {
printf("yep\n");
}


Jack Young写道:
Jack Young wrote:
嗨:
有关C编程的问题:
只使用一个C语句来检查一个变量是否是2的幂。不允许
循环。
等待你的答案。我几天没有睡好了。
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.




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问题。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆